Skip to content

Instantly share code, notes, and snippets.

Avatar

Gil Tayar giltayar

View GitHub Profile
@giltayar
giltayar / todo-list.test.js
Last active Dec 21, 2017
Companion code to an article
View todo-list.test.js
const webdriver = require('selenium-webdriver')
const {By, until} = webdriver
require('chromedriver')
describe.only('todo list', function() {
let driver
beforeAll(async () => (driver = await new webdriver.Builder().forBrowser('chrome').build()))
afterAll(async () => await driver.quit())
View selenium-webdriver-async-await.js
const {Builder, By, Key, until} = require('selenium-webdriver');
async function main() {
let driver = await new Builder()
.forBrowser('firefox')
.build();
await driver.get('http://www.google.com/ncr')
const element = await driver.findElement(By.name('q'))
View selenium-webdriver-promise.js
const {Builder, By, Key, until} = require('selenium-webdriver');
let driverPromise = new Builder()
.forBrowser('firefox')
.build();
driverPromise.then(driver => driver.get('http://www.google.com/ncr'))
.then(() => driver.findElement(By.name('q')))
.then(element => element.sendKeys('webdriver', Key.RETURN))
.then(() => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
View selenium-webdriver-no-async.js
const {Builder, By, Key, until} = require('selenium-webdriver');
let driver = new Builder()
.forBrowser('firefox')
.build();
driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
driver.quit();
View javascript-async-await-io.js
async function main() {
const content = await readFilePromise('source.txt')
await writeFilePromise('target.txt', content)
console.log('done')
}
main()
View javascript-promise-io.js
readFilePromise('source.txt')
.then(content => writeFilePromise('target.txt', content))
.then(() => console.log('done'))
View javascript-async-io.js
fs.readFile('source.txt', (_, content) => {
fs.writeFile('target.txt', content, () => {
console.log('done!')
})
})
View java-sync-io.java
byte[] content = Files.readAllBytes(Paths.get("source.txt"));
Files.write(Paths.get("target.txt"), content);
View e2e-stabilization-wait.js
await retry(async () => {
const displayElement = await driver.findElement(By.css('.display'))
const displayText = await displayElement.getText()
expect(displayText).to.equal('0')
})
View eyes-test.js
it('should look good', async function () {
await driver.get('http://localhost:8080')
await eyes.checkWindow('Initial Page')
const digit4Element = await driver.findElement(By.css('.digit-4'))
const digit2Element = await driver.findElement(By.css('.digit-2'))
const operatorMultiply = await driver.findElement(By.css('.operator-multiply'))
const operatorEquals = await driver.findElement(By.css('.operator-equals'))