Sahi Pro - Multiple modes/application types
Multiple modes in a script
It is now possible to interact with multiple application types from the same script. The application types are BROWSER, ANDROID, ANDROIDBROWSER.The appropriate mode needs to be set using _setMode and further steps will interact with that application type. BROWSER refers to Desktop Browser, ANDROID refers to Android Native, ANDROIDBROWSER refers to Android Browser.
A script can switch between different modes. Once the BROWSER mode is set, _launchNewBrowser is used to launch a new browser and _selectBrowser is used to select the particular browser to address the steps to.
In ANDROID mode, one would use _connectDevice to connect to a device and _selectDevice would be used to select the device.
In ANDROIDBROWSER mode, one would use _launchNewMobileBrowser to launch a mobile browser and _selectBrowser would be used to select the browser.
Once a browser, mobile browser or device has been launched/connected to, the script would only select the particular connection using the appropriate _selectZZZ API.
Refer to scripts in
userdata/scripts/demo/android
for usage examples.Playback: Default Desktop Browser and Mobile Device options
Before running a script/suite, the user has to choose the Default Desktop Browser, and Default Mobile Device.Playback: Start With option
The user also has to choose the mode in which to start the script. As of now, the options are Desktop Browser, Mobile Browser, Mobile Device and Generic.Mobile Device refers to Mobile Native.
Notes on Default and Start With options
-
When "Desktop Browser" is chosen as the Start With option, a browser of the Default Desktop Browser type is started automatically at the start of the script. This browser session is automatically selected, so that the first step in the script is addressed to this browser instance.
-
When "Mobile Browser" is chosen as the Start With option, a browser is started automatically on the Default Mobile device at the start of the script. This browser session is automatically selected, so that the first step in the script is addressed to this browser instance.
-
When "Mobile Device" is chosen as the Start With option, a native device connection is started automatically with the Default Mobile device at the start of the script. This device session is automatically selected, so that the first step in the script is addressed to this device instance.
-
When "Generic" is chosen as the Start With option, no device connection or browser launch is made. The script has to explicitly set the mode first using _setMode, and then do a _launchNewBrowser, _launchNewMobileBrowser or _connectDevice explicitly and then select that session using _selectBrowser, _selectBrowser or _selectDevice appropriately, before steps can be executed.
-
A new Desktop browser instance can be launched from the script using _launchNewBrowser. If browserType is not specified, a new browser of the default browser type is launched. Else a new browser of the specified browser type is launched. This instance can be selected as _selectBrowser($newInstanceId).
-
A new Mobile browser instance can be launched from the script using _launchNewMobileBrowser. If "Start With" was "Mobile Browser", then a deviceId different from the default mobile device is mandatory since one device can have only one browser session at a time. If "Start With" was something else, then _launchNewMobileBrowser will launch a mobile browser on the default device if no deviceId was specified, else on the specified device. This instance can be selected as _selectBrowser($newInstanceId).
-
A new device can be connected to from the script using _connectDevice. If "Start With" was "Mobile Device", then a deviceId different from the default mobile device is mandatory since one device can have only one native connection at a time. If "Start With" was something else, then _connectDevice will connect to the default device if no deviceId was specified, else to the specified device. This instance can be selected as _selectDevice($newInstanceId).
-
Once a browser session has been launched or a device session has been connected, it persists till the end of the script. Hence do not try to relaunch an already launched browser or reconnect to a connected device.
-
To switch between different Desktop browsers, one would simply do _selectBrowser of the appropriate browser session.
-
To switch between different mobile browsers, one would simply do _selectBrowser of the appropriate browser session.
-
To switch between different mobile devices, one would simply do _selectDevice of the appropriate device session.
-
To switch across different modes, the user would first do a _setMode with values BROWSER, ANDROID or ANDROIDBROWSER, and then do a _selectBrowser or _selectDevice.
-
The session that is launched automatically based on the "Start With" option, is called the base session. To return to a BROWSER or ANDROIDBROWSER base session, you can simply use _selectBrowser(), without a session id. This will select the base browser session id.
To return to a ANDROID base session, you can simply use _selectDevice(), without a session id. This will select the base device session id.