From ed0f65a04c52622115b30d918ece13fb22a9ff73 Mon Sep 17 00:00:00 2001 From: Marohn Howard Date: Fri, 20 May 2022 12:33:55 -0600 Subject: [PATCH] solution for 2.7.1 --- 2.7-Solution/SpecPage.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 2.7-Solution/SpecPage.ts diff --git a/2.7-Solution/SpecPage.ts b/2.7-Solution/SpecPage.ts new file mode 100644 index 000000000..6c1a0e1f8 --- /dev/null +++ b/2.7-Solution/SpecPage.ts @@ -0,0 +1,34 @@ +import { By, WebDriver, until} from "selenium-webdriver"; + + +export class SpecPage { + driver: WebDriver; + + url: string = "https://www.google.com"; + + searchBar: By = By.name('q') + results: By = By.id("rso") + + constructor(driver: WebDriver) { + this.driver = driver; + } + + async navigate() { + await this.driver.get(this.url) + await this.driver.wait(until.elementLocated(this.searchBar)) + } + async sendKeys(elementBy: By, keys) { + await this.driver.wait(until.elementLocated(elementBy)) + return this.driver.findElement(elementBy).sendKeys(keys) + } + async getText(elementBy: By) { + await this.driver.wait(until.elementLocated(elementBy)) + return (await this.driver.findElement(elementBy)).getText() + } + async doSearch(text: string) { + return this.sendKeys(this.searchBar, `${text}\n`) + } + async getResults() { + return this.getText(this.results) + } +} \ No newline at end of file