Set up and Develop Appium UWP RSpec Test Scripts with TestWise IDE

A step by step guide (with video) to create a test project for a Appium WinAppDriver+RSpec test script for UWP in TestWise IDE.

Courtney Zhan
5 min readNov 19, 2023

Universal Windows Platform (UWP) is relatively new app format from Microsoft to be used Windows devices (including mobile). For examples, The Calcuator App comes with Windows 10+ is a UWP.

The video below uses an Appium + WinAppDriver script to:

  • Launch the TestWise IDE.
  • Create a new Appium WinAppDriver + RSpec test project in TestWise IDE.
  • Script an Appium script to drive the Calculator UWP.
  • Execute the newly created Appium test.

All ~60 seconds. (fully automated, no human intervention)

If this all sounds familiar, I did another article previously on setting up and automating the Windows Calculator app here; this article is more of a quick start guide to automating the Windows Calculator app with TestWise.

Prerequisites

1. Install Appium Server and it is up running

  • Install Node.js
  • Install Appium 2
    npm install -g appium
  • Install Appium WinAppDriver
    appium driver install windows
  • Start Appium Server
    appium

All the commands run in a command window,

2. Install Ruby and Test libraries

  • Install Ruby
    Check out this guide in my other article.
  • Install Ruby Appium and Test libraries
    gem install — no-document appium_lib rspec

1. Verify Test Execution Setup

I have a habit of immediately verifying the operation. Execute the following commands in a terminal.

> cd 
> git clone https://github.com/testwisely/buildwise-samples.git

If you don’t use Git (for version control), I highly encourage learning it, 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 ~/buildwise-samples . In the same terminal window, run the two commands (one by one)

> cd buildwise-samples\e2e-rspec-appium-windows\spec
> rspec calc_add_raw_spec.rb

You shall see a Calculator window open and calculate 4 + 3 — 2.

2. Install TestWise IDE

Since the Appium RSpec test scripts are Ruby files, you may use any programmer editor, such as Visual Studio Code or Ruby-specific IDEs, such as RubyMine.

TestWise IDE is a Next-Gen Functional Testing IDE designed for E2E testing. I learned Test Automation with TestWise(Disclaimer: My father created TestWise). You may use TestWise in free mode with just minor constraints (relaunch the app after 15 test executions).

You may choose any tool to develop Appium test scripts (in plain text). That’s the beauty of being open-source and in a well-known language.

If you are not using TestWise, I encourage you to explore the test project structure that TestWise uses. It is simple and embraces the Maintainable Automated Test Design, which has been well-proven in many successful test automation projects. You can take advantage of the proven structure and supporting files (e.g. helper and page classes) even using a different testing tool.

3. Create a Test Project and your first Selenium RSpec test script in TestWise IDE.

TestWise uses the concept of ‘Project’ to confine the test scripts and supporting files.

1. Click menu ‘File’ > “New Project”.

Fill in the following information:

Project name: <any text>
Location: <an empty folder>
Automation Driver: Appium
Test Script Syntax: RSpec
UWP App ID: <UWP App ID>

To find the UWP of an app, follow the guide in this article.

2. Click the “OK” button to create the test project.

Here is how the test project’s skeleton looks like in TestWise.

A brief explanation of the folder and files:

  • spec Folder:
    Contains test script files in the format of XXX_spec.rb
  • pages Folder:
    Contains the page classes (see Page Object Model), the abstract_page.rb is already created.
  • test_helper.rb
    Shared test helper (see Maintainable Automated Test Design)
  • Rakefile & buildwise.rake
    For integrating with the BuildWise CT Server.
  • agileway_utils.rb
    For integrating with the TestWise IDE.
  • XXX.tpr File
    TestWise project file.

4. Create your first Appium WinAppDriver RSpec test in TestWise IDE.

Now, let’s create a raw Appium WinAppDriver RSpec test script quickly in TestWise.

3. Run the empty test script

Click new_spec.rb (in the PROJECT EXPLORER pane on the left) to open in an editor.

Right-click any line in the test case it "Test Case Name" do and select “Run “Test Case Name”” to run this individual test case.

You shall see a Calculator app launch.

This means that the test setup is fine.

4. Write Appium test statements in TestWise.

Here, I won’t explain Appium script syntax, for that, check out my father’s book “Practical Desktop App Test Automation with Appium”.

If you are already familiar with Selenium WebDriver and TestWise, you understand immediately. Below is an example.

driver.find_element(:name, "One").click()

For this exercise, this Appium script does the following.

  • Launch Calculator
  • Click button “1”
  • Click the button “+”
  • Click the button “3”
  • Click the button “=”
  • Assert the result is “4”

Test Script

Automation Framework: Appium 2 (v2.1.3, WinAppDriver: 2.12.1)
Test Syntax Framework : RSpec

load File.dirname(__FILE__) + "/../test_helper.rb"

describe "07 Create a new Appium WinApp UWP RSpec project" do
include TestHelper

before(:all) do
# close_all_testwise

custom_caps = {}
@driver = $driver = if Appium::VERSION.to_i >= 12
# Appium Lib Version => Appium Version, 12 for Appium 2
Appium::Driver.new(testwise_appium2_opts(custom_caps)).start_driver
else
Appium::Driver.new(testwise_caps(custom_caps), true).start_driver
end
sleep 0.5 # add a sleep for app window to show up
@main_window = MainWindow.new(@driver, testwise_version + " - AgileWay")
end

before(:each) do
sleep 0.5
@main_window.send_keys([:control, :shift, "n"])
sleep 0.25
end

after(:each) do
sleep 0.1
@main_window.send_keys([:control, :shift, "x"]) # close project
end

after(:all) do
sleep 0.1
driver.quit unless debugging?
end

it "07 New Appium UWP RSpec project" do
new_project_dir = tmp_dir("t7")
FileUtils.rm_rf(new_project_dir) if Dir.exist?(new_project_dir)
FileUtils.mkdir_p(new_project_dir)
puts("will create a new project in this dir: #{new_project_dir}")

new_project_dialog = NewProjectDialog.new(driver)
new_project_dialog.enter_title("T7")
new_project_dialog.enter_location(new_project_dir)
new_project_dialog.click_driver_framework_appium
new_project_dialog.clear_url
new_project_dialog.click_app_type_uwp
new_project_dialog.enter_url("Microsoft.WindowsCalculator_8wekyb3d8bbwe!App")
new_project_dialog.click_ok

sleep 0.5
open_file("new_spec")

sleep 0.5
editor_text = get_current_editor_text()
expect(editor_text).to include("Appium::Driver")

goto_line("18, 15")
main_window.send_keys([:control, "i"])
main_window.send_keys("Calc- Add")
main_window.send_keys(:down)

main_window.send_keys([:control, :shift, "c"], :backspace)
sleep 0.25

#main_window.send_keys("driver.find_element(:id, \"username\").send_keys(\"agileway\")", :enter)
main_window.send_keys("dfen", :tab, "One", :tab, ".click", :tab, :enter)
main_window.send_keys("dfen", :tab, "Plus", :tab, ".click", :tab, :enter)
main_window.send_keys("dfen", :tab, "Three", :tab, ".click", :tab, :enter)
main_window.send_keys("dfen", :tab, "Equals", :tab, ".click", :tab, :enter)

main_window.send_keys("result = driver.find_element(:accessibility_id, \"CalculatorResults\").text", :tab, :enter);
main_window.send_keys("exp", :tab, "result", :tab, :tab, 'eq("Display is 4")', :tab, :enter)
sleep 1

main_window.click_tool_run_test_file

sleep 10

run_results = ""
try_for(9, 3) {
run_results = get_current_run_panel_csv
puts run_results.inspect
expect(run_results).to include("OK")
}
end
end

--

--