Installing RanorexDriver on the local address and port of your choice
- Download Ranorex Studio with RanorexDriver:
Download the special Ranorex Studio installer from this shared folder. Use the zip version if you do not want to install anything. - Open a terminal, navigate to the Ranorex bin directory and start RanorexDriver.exe
The default endpoint url is http://localhost:7993/ . Address and port can be changed with -address=ip and -port=port command-line arguments:C:\Program Files(x86)\Ranorex\Studio\Bin\RanorexDriver.exe" -address:YourIpAddress -port:portNumber
- If the RanorexDriver service started successfully, you should see the following output:
driver = webdriver.Remote("http://127.0.0.1:7993", { # Set Ranorex as the remote browserName "browserName": "Ranorex", # In the rx:app field, place the name or the path to the application under test! "rx:app": "path/to/app.exe", # Arguments for the application to start "rx:args": "", # Forces the current session to be aborted an restarted "rx:force": True, # Additional process names to whitelist for the session "rx:whitelist": ["PROCESS NAME(S)"] })
- RanorexDriver uses the browserName “Ranorex” in the desired capabilities.
- For starting an app, the “rx:app”:“path/to/app.exe” capability can be used.
- Only one concurrent session is supported (because of Mouse/Keyboard input)
- Selectors need to be in RxPath format, but “xpath” can be used from the client (e.g. find_element_by_xpath)
- Selectors can be copied from Ranorex Spy (e.g. /form/button[@name=‘Foo’])
- Started processes (through rx:app or POST /url) are automatically added to the process whitelist
Make a test and run it
For creating the actual test, you can use a programming language and an IDE of your choice.
In this example, we will make a test using Python and Visual Studio Code, so let’s get started:
- Make sure that Python is installed and set in your PATH environment variable.
- Make sure Selenium is installed
Install the selenium package using pip install selenium on the command line. - Create the DriverSetup.py
Now we will create the DriverSetup.py file where we will set up the Ranorex Driver and pass it to the Selenium Remote WebDriver as a parameter.
We need to provide the IP address and port on which we have started the RanorexDriver, as well as some additional parameters like the browser name, location (path) to our application under test, start parameters, etc.
from selenium import webdriver # Ranorex Driver Setup driver = webdriver.Remote("http://127.0.0.1:7993", { # Set Ranorex as the remote browserName "browserName": "Ranorex", # In the rx:app field, place the name or the path to the application under test! "rx:app": "calc", # Arguments for the application to start "rx:args": "", # Forces the current session to be aborted an restarted "rx:force": True, # Additional process names to whitelist for the session "rx:whitelist": ["Calculator"] })
After we have set up the Ranorex Driver, we will create the Elements.py file where we will place all of the selectors created with Ranorex Spy, and add the actions to them so that we have a Page Object Pattern-like maintainable project.
The Selectors need to be in RxPath format as created in the Ranorex Spy, and you can use the
find_element_by_xpath() method to add the necessary actions:from DriverSetup import driver # Generated Selecotrs: Number2 = driver.find_element_by_xpath("/winapp[@packagename='Microsoft.WindowsCalculator']/?/?/container[@automationid='NumberPad']/button[@automationid='num2Button']") AdditionBtn = driver.find_element_by_xpath("/winapp[@packagename='Microsoft.WindowsCalculator']/?/?/container[@automationid='StandardOperators']/button[@automationid='plusButton']") EqualsBtn =driver.find_element_by_xpath("/form") Result = driver.find_element_by_xpath("/winapp//text[@automationid='NormalOutput']") # Generated Actions: ClickNumberTwo = Number2.click() ClickAdditionButton = AdditionBtn.click() ClickEqualsButton = EqualsBtn.send_keys("=") GetResult = Result.text
- Create the CalculatorTest.py
Finally, we will create the calculatorTest.py file and finalize our test. Import the remote driver from our driverSetup.py and all the elements from the selector.py modules and let the testing begin!from selenium import webdriver from selenium.webdriver.common.keys import Keys from Elements import * # Test steps - execute the 2+2=4 calculation ClickNumberTwo ClickAdditionButton ClickNumberTwo ClickEqualsButton # Assert the result if "4" in GetResult: print("Test passed, the result is: " + GetResult), else: print("Error, test failed...") # End the test and close the driver driver.close()
And there you have it! The test is done and completed successfully.
We have located the calculator elements and generated the appropriate selectors with Ranorex Spy. After that, all you need to do is to set up the RanorexDriver as a RemoteWebDriver, add the actions and run the test.
Automating desktop applications isn’t hard at all with the help of the RanorexDriver and Ranorex Spy. You can find more information about Ranorex Driver in the readme file provided in the Ranorex Driver folder