Skip to content

Instantly share code, notes, and snippets.

@Kameshwaran
Created July 8, 2018 16:24
Show Gist options
  • Save Kameshwaran/49cc1541db8aec1c07ec29f6712b7b75 to your computer and use it in GitHub Desktop.
Save Kameshwaran/49cc1541db8aec1c07ec29f6712b7b75 to your computer and use it in GitHub Desktop.
selenium test
const { Builder, By, until } = require('selenium-webdriver');
const driver = new Builder()
.forBrowser('chrome')
.build();
const waitForTitle = () => {
return driver.getTitle().then((title) => title.includes('JSFiddle'));
}
const runTests = () => {
return new Promise(async (onDone, onError) => {
const totalNumberOfTests = 2;
let testsPassed = 0;
try {
driver.switchTo().frame(driver.findElement(By.tagName('iframe')));
var square = driver.findElement(By.id('square'));
var button = driver.findElement(By.id('button'));
const borderRadius = await square.getCssValue('border-radius');
const backgroundColor = await square.getCssValue('background-color');
button.click();
const newBorderRadius = await square.getCssValue('border-radius');
const newBackgroundColor = await square.getCssValue('background-color');
if (borderRadius !== newBorderRadius && parseInt(newBorderRadius) > 45) { return testsPassed++; }
if (backgroundColor !== newBackgroundColor) { return testsPassed++; }
onDone(testsPassed, totalNumberOfTests);
return driver.wait(waitForTitle, 1500);
}
catch(e) {
onError(e);
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment