Last active
January 5, 2019 10:42
-
-
Save M-Izadmehr/dbe58110b1be4ac1f5de95a1d3f60a55 to your computer and use it in GitHub Desktop.
End-to-End (E2E) code samples: searching medium
This file contains 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
/** | |
* here we import the selenium module | |
*/ | |
const webDriver = require('selenium-webdriver'); | |
/** | |
* these are the main functionalities of webdriver | |
* By allows us to find elements | |
* Key allows us to simulate keyboard keys | |
* until helps us to wait until a certain criteria is met (for example element is visible) | |
*/ | |
const { By, Key, until } = webDriver; | |
/** | |
* here we create the webdriver, and tell it to open the browser. | |
* You should already have installed chrome-driver. | |
*/ | |
const driver = new webDriver.Builder().forBrowser('chrome').build(); | |
const perform = async () => { | |
/** | |
* here we redirect the medium search | |
*/ | |
await driver.get('https://medium.com/search'); | |
/** | |
* then we find the search input and change the values, and finally press enter button | |
*/ | |
const searchElement = await driver.findElement( | |
By.css('form [type="Search"]'), | |
); | |
await searchElement.sendKeys('Izadmehr'); | |
await searchElement.sendKeys(Key.ENTER); | |
/** | |
* here we find describe the css selector to my profile | |
* then we wait, until this element is located, | |
* and finally click it | |
* @type {!By} | |
*/ | |
const usernameLink = By.css('[data-user-id="43f4a4c78443"]'); | |
const usernameElement = driver.wait(until.elementLocated(usernameLink)); | |
await usernameElement.click(); | |
/** | |
* Here our test process is done, and we should be successfully redirected to my profile page | |
* We can write some test scenarios based on this condition | |
*/ | |
}; | |
perform(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment