docs: update docs how to use Selenium
This commit is contained in:
parent
e3cf12addf
commit
429d53d738
|
|
@ -1382,25 +1382,43 @@ Run a shell command directly on your phone.
|
|||
You can use Selenium directly if you need to use things that are not available through our commands.
|
||||
|
||||
You get a hold of the Selenium objects through the context.
|
||||
The *selenium.webdriver* that is the Selenium [WebDriver public API object](https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index.html). And *selenium.driver* that's the [instantiated version of the WebDriver](https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html) driving the current version of the browser.
|
||||
The *selenium.webdriver* is the Selenium [WebDriver public API object](https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index.html). And *selenium.driver* is the [instantiated version of the WebDriver](https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html) driving the current version of the browser.
|
||||
|
||||
Checkout this example to see how you can use them.
|
||||
|
||||
~~~javascript
|
||||
module.exports = async function(context, commands) {
|
||||
// we fetch the selenium webdriver from context
|
||||
const webdriver = context.selenium.webdriver;
|
||||
const driver = context.selenium.driver;
|
||||
// before you start, make your username and password
|
||||
const userName = 'YOUR_USERNAME_HERE';
|
||||
const password = 'YOUR_PASSWORD_HERE';
|
||||
const loginForm = await driver.findElement(webdriver.By.css('form'));
|
||||
const loginInput = await driver.findElement(webdriver.By.id('wpName1'));
|
||||
await loginInput.sendKeys(userName);
|
||||
const passwordInput = await driver.findElement(webdriver.By.id('wpPassword1'));
|
||||
await passwordInput.sendKeys(password);
|
||||
// this example skips waiting for the next page and validating that the login was successful.
|
||||
return loginForm.submit();
|
||||
// We fetch the selenium webdriver from context
|
||||
// The selenium-webdriver
|
||||
// https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/index.html
|
||||
const seleniumWebdriver = context.selenium.webdriver;
|
||||
// The driver exposes for example By that you use to find elements
|
||||
const By = seleniumWebdriver.By;
|
||||
|
||||
// We use the driver to find an element
|
||||
const seleniumDriver = context.selenium.driver;
|
||||
|
||||
// To navigate to a new page it is best to use our navigation commands
|
||||
// so the script waits until the page is loaded
|
||||
await commands.navigate('https://www.sitespeed.io');
|
||||
|
||||
// Lets use Selenium to find the Documentation link
|
||||
const seleniumElement = await seleniumDriver.findElement(By.linkText('Documentation'));
|
||||
|
||||
// So now we actually got a Selenium WebElement
|
||||
// https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebElement.html
|
||||
context.log.info('The element tag is ', await seleniumElement.getTagName());
|
||||
|
||||
// We then use our command to start a measurement
|
||||
await commands.measure.start('DocumentationPage');
|
||||
|
||||
// Use the Selebium WebElement and click on it
|
||||
await seleniumElement.click();
|
||||
// We make sure to wait for the new page to loead
|
||||
await commands.wait.byPageToComplete();
|
||||
|
||||
// Stop the measuerment
|
||||
return commands.measure.stop();
|
||||
}
|
||||
~~~
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue