public final class SeleniumPlugin extends PluginAncestor
Selenium plugin provides a set of MScript functions to suplement Selenium/WebDriver to test web applications using various browsers of choice. It also provides access to "webDriver" object that allows you to call "webDriver" native functions. For example:
$SELENIUM.getWebDriver().findElement(By.id('F1')).click();
For more information about Selenium (WebDriver), please refer to its website: https://www.selenium.dev/documentation/en/Check out Michael Sorens' post on Selenium locators.
You can load test your web application by setting the appropriate "virtual user" in MBT Settings for most of the browsers, though Htmlunit headless browser type is preferred for load testing.
MBT server comes with an embedded Selenium/WebDriver server. You may run your models using SeleniumRC/Grid and cloud services like SauceLabs.com.
You may also use one of the setCapability methods to set/change WebDriver's browser capabilities as supported by WebDriver.
Example:$SELENIUM.getDriverOptions().setCapabilityString('chrome.switches', 'load-extension=/path/to/unpacked_extension', ' ')
For more details about capabilities, see http://code.google.com/p/selenium/wiki/DesiredCapabilities Mobile Testing:
For iPhone, iPad and Android testing, this is done through one of the following:
All of the above requires that you set WebDriver Capabilities. You may find more information about the WebDriver Capabilities settings on internet, e.g. https://docs.saucelabs.com/tutorials/appium/.
Modifier and Type | Class and Description |
---|---|
static class |
SeleniumPlugin.BrowserType |
MScriptInterface.IGNORE_INHERITED_METHOD, MScriptInterface.NOT_MSCRIPT_METHOD, MScriptInterface.TO_PLUGIN
Constructor and Description |
---|
SeleniumPlugin() |
Modifier and Type | Method and Description |
---|---|
SeleniumAssist |
assist()
returns the helper class that contains helper functions for more complex ui operations.
|
void |
close()
INTERNAL USE ONLY
|
org.openqa.selenium.remote.DesiredCapabilities |
getDesiredCapabilities()
returns the DesiredCapabilities object.
|
org.openqa.selenium.MutableCapabilities |
getDriverOptions()
returns the browser driver capabilities object.
|
String |
getPluginDesc() |
String |
getPluginID() |
org.openqa.selenium.remote.RemoteWebDriver |
getRemoteWebDriver()
cast webdriver into RemoteWebDriver unless its HTMLUnit in which case it returns null.
|
org.openqa.selenium.WebDriver |
getWebDriver()
returns WebDriver object which is used to interact with web element.
|
void |
initialize(MbtScriptExecutor scriptExec_p)
INTERNAL USE ONLY
|
void |
setBrowser(String browserType_p)
sets browser type to test AUT.
|
void |
setBrowserChrome() |
void |
setBrowserEdge() |
void |
setBrowserFirefox() |
void |
setBrowserHtmlunit() |
void |
setBrowserIE()
changes the browser to be used for execution.
|
void |
setBrowserOpera() |
void |
setBrowserSafari() |
void |
setSysProp(String propName_p,
String propValue_p)
sets System properties before browser webdriver connection is established.
|
void |
setWebDriver(org.openqa.selenium.remote.RemoteWebDriver webDriver_p)
sets webDriver to be used for automation.
|
String |
snapScreen(String fn_p)
Take a snapshot of current AUT window.
|
void |
start()
INTERNAL USE ONLY
|
enterInitialState, exitFinalState
public org.openqa.selenium.WebDriver getWebDriver()
public org.openqa.selenium.remote.RemoteWebDriver getRemoteWebDriver()
public void setWebDriver(org.openqa.selenium.remote.RemoteWebDriver webDriver_p)
webDriver_p
- public void close()
INTERNAL USE ONLY
close
in class PluginAncestor
public void initialize(MbtScriptExecutor scriptExec_p)
INTERNAL USE ONLY
public void start() throws Exception
INTERNAL USE ONLY
start
in class PluginAncestor
Exception
public void setSysProp(String propName_p, String propValue_p) throws Exception
propName_p
- propValue_p
- Exception
public String snapScreen(String fn_p) throws Exception
Typical use of this method is to call it in MBT_FAIL or MBT_ERROR trigger to take a snapshot of the screen of the error.
The screen shot will be marked with the first exception (if multiple exceptions) triggered by current mScript and thus available from the exception popup.
Example:$SELENIUM.snapScreen('myFileName');
fn_p
- name of the file, final file name will suffixed with "_timestamp".Exception
public String getPluginID()
getPluginID
in class PluginAncestor
public void setBrowserIE() throws MBTAbort
Example:
$SELENIUM.setBrwoserIE();
MBTAbort
public void setBrowser(String browserType_p) throws MBTAbort
For example iexplore for IE, firefox for Firefox, custom c:/xxxx/yy.exe for custom browser to run a specific exe.
sIf other value is passed, it will default to Chrome.
You may also call specific function to set the browser type, e.g. setBrowserIE(), setBrowserFirefox(), etc.
browserType_p
- MBTAbort
public String getPluginDesc()
getPluginDesc
in class PluginAncestor
public org.openqa.selenium.MutableCapabilities getDriverOptions()
public org.openqa.selenium.remote.DesiredCapabilities getDesiredCapabilities()
public SeleniumAssist assist()
Copyright TestOptimal, LLC