Tie "Runs with" execution setting within test case steps

I need help working an all inclusive test case/test suite collection execution.

In my test case I need to specify run with to determine if the testing will run the mobile app, web mobile or desktop web testing.

Here is a rudimentary concept of what I’m asking for:

Test Suite Collection Execution Settings:

No. ID **Run with ** Run configuration Profile Run
1 Test Suite Name Chrome Default X
2 Test Suite Name Kobiton Device Galaxy S6 Edge 6.0.1 Default X
3 Test Suite Name Kobiton Device Nexus 5 4.4.4 Default X

Run with
The selection of “Chrome” runs the test suite on the desktop Chrome browser for desktop web testing.
The selection of “Kobiton Device - Galaxy S6 Edge 6.0.1” runs the test suite on the Chrome browser for web mobile testing.
The selection of “Kobiton Device - Nexus 5 4.4.4” runs the test suite as mobile app testing.

Then Determine which selection from above to run the appropriate test steps for mobile app, web mobile or desktop web testing.

Within the test case:

if (Nexus 5 4.4.4 - determined from the run with executions settings) {
Mobile.startApplication(‘kobiton-store:####’, true)
Mobile.closeApplication()
} else {
WebUI.openBrowser(’’)
WebUI.closeBrowser()
}

Problem - I’m not exactly sure, but I believe “Mobile.” and “WebUI.” set the type of testing before desired capabilities can even be determined (i.e. “WebUI.openBrowser” executes before “deviceName”, “platform”, etc. are retrieved…but “runs with” is determine before the test case even starts.

How can I tie the execution settings into test steps in order to run the correct type of testing on a specific device/browser?

I figured out a simple solution:

  1. Create two different profiles - ExecuteAppTesting and ExecuteWebTesting
    a) In each one add the same global variables - appTest and webTest
    b) Set appTest to true and webTest to false in ExecuteAppTesting
    c) Set the boolean opposite in ExecuteWebTesting for the two variables

  2. In the test case add a conditional statement

if (GlobalVariable.mobileTest) {
Mobile.startApplication(‘kobiton-store:####’, true)
Mobile.closeApplication()
} else if (GlobalVariable.webTest) {
WebUI.openBrowser(’’)
WebUI.closeBrowser()
}

  1. In the test suite collection setup the execution to incorporate the two different profiles

No. ID Run with Run configuration Profile Run
1 Test Suite Name Chrome ExecuteWebTesting X
2 Test Suite Name Kobiton Device Galaxy S6 Edge 6.0.1 ExecuteWebTesting X
3 Test Suite Name Kobiton Device Nexus 5 4.4.4 ExecuteAppTesting X