TestWise Execution Setup
In fact, it is a set-up of test automation execution.
This article is for users who just downloaded the standard TestWise IDE (not TestWise Ruby Edition for Windows, which is all pre-packaged), and are keen to set up to execute one automated test script.
Table of Content:
· 0. Test Harness: Running a Selenium-RSpec tests from a Terminal
· 1. Install Ruby Language Runtime
∘ Windows
∘ macOS
· 2. Browser
· 3. Testing Libraries
· 4. ChromeDriver
∘ Download
∘ Move “chromedriver” execuable to PATH
∘ Pass Verification (macOS only)
· 5. Running in TestWise
After a user launches TestWise the first time,
If you are not seeing the above, click menu ‘Tools”->”Toggle Start Page”.
He/she most likely clicks “Open Sample Project (web app)” (Yes, a correct guess), and try to run a sample test script (Yes, good thinking).
He/she was expecting a Chrome browser to be launched to run an automated test, but might not happened. This is because the test automation execution environment is not set up (The TestWise part is done or nearly done).
TestWise Ruby Edition on Windows has everything packaged, so a new user would see test execution immediately. AgileWay expects macOS/Linux users are more advanced, after all, setting up test automation execution (independent from any vendor tool) is preferred.
In this article, I will show how, in very simple steps (quickly). Please note, this only needs to be done once.
To run a web test automation scripts, there are four essential components that need to be installed (or configured properly):
- Language runtime
In this case, Ruby. You can use TestWise to develop automated E2E tests in JavaScript and Python. AgileWay, at present, only officially supports Ruby, the best scripting language for E2E Test Automation. After all, Ruby is rated “the most in-demand skill”, according to Hired’s 2023 State of Software Engineers Report. - Browser, i.e. Chrome.
- Testing Libraries, e.g. Selenium WebDriver
- Browser Driver, e.g. ChromeDriver
Quite logical, right? Let’s do it step by step.
0. Test Harness: Running a Selenium-RSpec tests from a Terminal
It is my habit to define the success factor first before a task, when possible.
Our goal: invoke a run of one test script test from a terminal to see it running in a Chrome browser window.
Next question: Where to get test script? Simple, AgileWay has already prepared for you. Execute the commands in a terminal.
% cd
% git clone https://github.com/testwisely/agiletravel-ui-tests
If you don’t know Git (for version control), you should, and it is quite easy to use. Check out 10-Minute Guide to Git Version Control for Testers.
You will find a set of folders and files under ~/agiletravel-ui-tests
. In the same terminal window, run the two commands (one by one)
cd agiletravel-ui-tests/selenium-webdriver-rspec/spec
rspec 01_login_spec.rb
You might get some errors, such as one below.
Quite clearly, this means missing ‘selenium-webdriver’ library.
For this step, we are done. We will re-run this command (in this directory) to verify the setup.
1. Install Ruby Language Runtime
Windows
Use RubyInstaller for Windows.
- Download a stable version
Unless you clearly know your choice, I would recommend Ruby + DevKit 3.2.2–1 (x64), as indicated above.
2. Installer
Double-click the downloaded package(about 130MB in size) and run the installer.
Click the “Install” button. On the next page, make sure “MSYS2 development toolchain …” is selected.
Continue with installation. After about 2 minutes later, you will see this.
Make sure the checkbox is checked (don’t change), and click the “Finish” button. But it is not finished, MSYS2 is yet to be installed. Soon, you will be presented with a black window like below.
Just press the “ENTER” key. Wait a bit.
Press the ENTER key, Done! By default, it is installed under the folder c:\Ruby32-x64
.
3. Verify
To verify, start a new command window, type ruby --version
followed by the ENTER key.
macOS
macOS comes with Ruby installed. The version (Monterey) is 2.6.
% ruby --version
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.x86_64-darwin21]
Ruby 2.6, quite dated, can be used for test automation. But I do recommend using the latest 3.2, as some libraries require version 2.7+.
Anyway, most Ruby developers/testers use rbenv
(a version manager for Ruby) to manage different versions of Ruby. It is quite easy to install rbenv, there are plenty guides online, such as this one.
Basically, four steps.
brew install rbenv ruby-build
rbenv install 3.2.2
rbenv global 3.2.2
ruby -v
The first step might take a while (a few minutes). The third step is to set the machine to use Ruby 3.2.2. The last step is to verify.
2. Browser
While Selenium works for all major browsers, let’s focus the dominant Chrome here.
There is no need to talk about Chrome installation. I just point out a new feature introduced in Selenium 4.11, “Chrome for Testing”. Read this article later, “Chrome for Testing” for Selenium v4.11+ and Chrome v115+.
3. Testing Libraries
Install Selenium WebDriver (automation framework) and RSpec (test syntax framework) in a new terminal window.
gem install --no-document selenium-webdriver rspec
Now, try to verify the test execution (Step 0).
If getting Gem::MissingSpecError
, just run another gem install MISSING
command to install it. For example, bundler
is a commonly used gem that help manage dependent gems (required by BuildWise).
gem install --no-document bundler
Hopefully, you will see test execution in a Chrome browser window. If not, there must be a missing chromedriver error.
4. ChromeDriver
As its name suggests, it drives Chrome.
Download
Installation is quite easy, go to https://googlechromelabs.github.io/chrome-for-testing/, download the one (clicking the ‘Stable’ link then choose ‘chromedriver’, ~8MB in size) for yours:
- Platform
macOS:mac-arm64
for Apple Silicon (M1, M2),mac-x64
for Intel
Windows:win64
- Browser version
macOS: Unzipped the downloaded file (chromedriver-mac-x64.zip
orchromedriver-mac-arm64.zip
), you will find an executablechromedriver
Windows:chromedriver.exe
Move the “chromedriver” execuable to PATH
Windows:
Copy the chromedriver.exe
to any folder in %PATH%. I recommend C:\Ruby32-x64\bin
.
macOS:
Open a new terminal, type mv
, then drag the chromedriver
executable to it, like below.
Then, continue typing /usr/local/bin
and run the command. The whole command will be
mv /Users/ME/Downloads/chromedriver-mac-x64/chromedriver /usr/local/bin
The reason: /usr/local/bin
is usually included in PATH.
Run this verification command:
chromedriver --version
Pass Verification (macOS only)
You will see this security warning (I think the ChromeDriver team, from Google, should become an Apple’s developer, anyway, it is free and open-source work, understandable for frequent releases. Also, maybe Apple should be more relaxing on this, not needed on Windows). Click the ‘cancel’ button.
Then open the “Security & Privacy’ in “System Preferences”,
Click the “Allow Anyway” button. Then rerun the chromedriver --version
command. You get this.
Click the “Open” button in the pop up window. You will get something like the below.
zhimin@iMac-Study ~ % chromedriver --version
ChromeDriver 116.0.5845.96 (1a391816688002153ef791ffe60d9e899a71a037-refs/branch-heads/5845@{#1382})
Please note, the above security annoyances only needed to be dealt with once, per chromedriver update.
The execution for Selenium + RSpec set-up is done. Now verify the test execution (Step 0).
Yes!
When setting up Continuous Testing, you must also perform the above. I did every step in detail. It might feel like a lot, but really, it is quite easy.
5. Running in TestWise
Back to our original purpose, running tests in TestWise.
Open TestWise setting (Tools -> TestWise settings, or Cmd + ,
), under the “Execution” tab.
You can see the execution path. I highlight the two
/Users/ME/.rbenv/shims
where Ruby (via rbenv) is/usr/local/bin
where chromedriver is
Now select the “Frameworks” tab, click the “Detect” button.
This one looks good.
Now rerun that 01_login_spec.rb
test script in the sample project.
Yes, saw the test execution. One test case failed (in red) was intentional.
Some astute readers wonder, “this is not the test I ran from the command line then”. A good question.
- Close the existing project.
click the menu ‘File’ -> “Close Project” - Open a new project,
click the menu ‘File’ -> ‘Open Project’, and select/Users/me/agiletravel-ui-tests/selenium-webdriver-rspec/ agiletravel-selenium-webdriver.tpr
The .tpr
file means a Test Project file for TestWise.
Run a different test script file, e.g. flight_spec.rb
, it shall work too.
To wrap this article, I will show a very useful way to execute a test case in TestWise (in fact, 99% of time, I run a test this way).
This test script, flight_spec.rb
, contains two test cases: “[3] Return trip” and “[2] One-way trip”.
Suppose I just want to run (for developing/debugging) the “[3] Return trip” test case (not all test cases in the test script file).
- Right-click any line within that test case (from lines 25–39)
2. Select “Run “[3]” Return trip”
in the context menu. (Notice the icon difference)
This time, only one test case is run. More importantly, the browser will be left open. This is very very useful for debugging and other purposes.
Check out the following articles: