How to connect to a Selenium server with code

Class library usage, coding and language questions.
jlroussel
Posts: 1
Joined: Mon Mar 28, 2022 4:06 pm

How to connect to a Selenium server with code

Post by jlroussel » Wed Sep 07, 2022 12:29 pm

Hello,
We are targetting to run our test using the BrowserStack services.
I have successfully added a Selenium test endpoint using Ranorex IDE. Using this endpoint, the test are running on Browser Stack with no issue.

Test will be run into an Azure Pipeline, i.e. command line. So we need to write some code in order to switch to the Browser Stack endpoint.

But I do not find any documentation that could help on that except the following post :
https://www.ranorex.info/automatic-endp ... 13867.html. That seems to be used to connect a new device (mobile, ...).

So the question could be rephrased is 'how to connect to a selenium end point using the Ranorex API ?'

Does any body have a clue on what to be done ?

apae
Posts: 5
Joined: Thu Dec 09, 2021 9:05 am

Re: How to connect to a Selenium server with code

Post by apae » Fri Sep 09, 2022 8:15 am

Hello,

It is possible, but you do need programming knowledge to set it up properly. I use RX with C# 7.0 and most of the programming I do with Visual Studio. RX Studio is not a great tool for coding.

I developed it so that it can be used with any SUT. Unfortunately I can't share code as it's not easy to share just this bit (it takes a lot more into account).

I build the endpoint based on an endpoint factory class. I am using RX api code for this. I'm not using Ranorex's Endpoint parameter and I'm not using a configured endpoint using Ranorex IDE!

Factory Design example https://dotnettutorials.net/lesson/fact ... rn-csharp/

I send my SUT name via the global parameter for command line execution and I use the local parameter if the global parameter is not used.
Local parameter is used if the test is always for the same SUT or if I just run it via the Ranorex Studio for test development and test maintenance

The command line looks like this:
    BrowserStack Browser testing
    rxtest.exe /ts:TS_Web.rxtst /pa:SUT=bsipadmini2021 /tc:TC_1 /pa: ...

    - RX Browser testing
    rxtest.exe /ts:TS_Web.rxtst /pa:SUT=rxchrome /tc:TC_1 /pa: ....

    - RX App testing
    rxtest.exe /ts:TS_App.rxtst /pa:SUT=rxwincalculator /tc:TC_1

    Setup contains code module StartAUT (start endpoint and opens the app or navigate to the url) and teardown contains code module StopAUT (stop endpoint)

    Based on the SUT name I set the BS Capabilities via a file SUTConfig.ini where all devices are configured that I need for BS in my case. You can do it also with a dictionary or xml, json …

    A SUTConfig.ini example:

    [bsw11firefox104]
    ; image is not BS capability
    image="bs_win11_firefox_104"
    os="Windows"
    os_version="11"
    browser="Firefox"
    browser_version="104.0"
    resolution="1920x1080"
    browserstack.selenium_version="3.141.0"

    [bsipadmini2021]
    ; image is not BS capability
    image="bs_ios15_ipad_mini_2021_safari"
    os_version="15"
    browser="safari"
    device="iPad Mini 2021"
    deviceOrientation="landscape"
    realMobile="true"
    browserstack.appium_version="1.22.0"

    The configuration for the other SUT (RX browser or Windows App) is done in the endpoint factory class.

    I hope my explanation helps you!

    apae
    Posts: 5
    Joined: Thu Dec 09, 2021 9:05 am

    Re: How to connect to a Selenium server with code

    Post by apae » Fri Sep 09, 2022 12:32 pm

    Hello,

    Another solution could be:

    yourexecutable.exe /? this shows all allowed arguments.
    Take a look for the following arguments:

    - endpoint|ep:<endpoint name>
    Display name of the endpoint to be used as the automation root during test execution.
    If no endpoint is specified 'localhost' is used.
    - endpointconfig|epc:<configuration name>
    Set the configuration that will be used for this endpoint during test execution.
    Not all endpoint types support configurations.
    - endpointconfigfilepath|epcfp: <configuration file path>
    Set the file path to the configuration that should be used for the endpoint during test execution.