Skip to content

Instantly share code, notes, and snippets.

@mauroao
Last active June 21, 2020 02:27
Show Gist options
  • Save mauroao/e25fdf8786f91d6d050eb8db1486784e to your computer and use it in GitHub Desktop.
Save mauroao/e25fdf8786f91d6d050eb8db1486784e to your computer and use it in GitHub Desktop.
javascript_page_objects
const { Builder } = require('selenium-webdriver');
require('chromedriver');
const Page = require('./page');
(async function example() {
const driver = await new Builder().forBrowser('chrome').build();
try {
const page = new Page(driver);
await page.openAndTestPage();
} finally {
await driver.quit();
}
})();
const { By, Key, until } = require('selenium-webdriver');
class Page {
constructor(driver) {
this.driver = driver;
}
async openAndTestPage() {
await this.driver.get('https://www.google.com');
await this.driver.findElement(By.name('q')).sendKeys('cheese', Key.ENTER);
const firstResult = await this.driver.wait(
until.elementLocated(By.css('h3>div')),
10000
);
console.log(await firstResult.getAttribute('textContent'));
}
}
module.exports = Page;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment