Last active
June 21, 2020 02:27
-
-
Save mauroao/e25fdf8786f91d6d050eb8db1486784e to your computer and use it in GitHub Desktop.
javascript_page_objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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