Created
January 13, 2020 21:51
-
-
Save amitzur/1d6f6e702029a7889dd972b9f4501c5e to your computer and use it in GitHub Desktop.
Example of using test result to show ouptut in Applitools' JS Selenium SDK
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
'use strict'; | |
const {Eyes, Target, TestResultsFormatter} = require('@applitools/eyes-selenium'); | |
const {Builder, By, Key} = require('selenium-webdriver'); | |
(async () => { | |
const eyes = new Eyes(); | |
const driver = new Builder().forBrowser('chrome').build(); | |
try { | |
await driver.get('http://todomvc-app-for-testing.surge.sh/'); | |
// To get visual diffs, use this link in subsequent runs | |
// await driver.get('http://todomvc-app-for-testing.surge.sh/?different-title-color'); | |
await eyes.open(driver, 'todomvc', 'create todos', { | |
width: 800, | |
height: 600, | |
}); | |
await eyes.check('initial', Target.window()); | |
const newTodoInput = await driver.findElement(By.css('.new-todo')); | |
await newTodoInput.sendKeys('buy some cheese') | |
await newTodoInput.sendKeys(Key.ENTER) | |
await eyes.check('one todo', Target.window()); | |
await newTodoInput.sendKeys('feed the cat') | |
await newTodoInput.sendKeys(Key.ENTER) | |
await eyes.check('two todos', Target.window()); | |
// to get a new step, uncomment the following in subsequent runs | |
// await eyes.check('new step', Target.window()); | |
const testResults = await eyes.close(false); | |
console.log(` | |
Test name : ${testResults.getName()} | |
Test status : ${testResults.getStatus()} | |
URL to results : ${testResults.getUrl()} | |
Total number of steps : ${testResults.getSteps()} | |
Number of matching steps : ${testResults.getMatches()} | |
Number of visual diffs : ${testResults.getMismatches()} | |
Number of missing steps : ${testResults.getMissing()} | |
Display size : ${testResults.getHostDisplaySize().toString()} | |
Steps : | |
${testResults.getStepsInfo().map(step => { | |
return ` ${step.getName()} - ${getStepStatus(step)}` | |
}).join('\n')} | |
========================================================= | |
`); | |
console.log('Built-in output format:') | |
const formatter = new TestResultsFormatter([testResults]); | |
console.log(formatter.asFormatterString()) | |
} finally { | |
await driver.quit(); | |
} | |
})().catch(err => { | |
console.log(err); | |
process.exit(1); | |
}) | |
function getStepStatus(step) { | |
if (step.getIsDifferent()) { | |
return 'Diff' | |
} else if (!step.getHasBaselineImage()) { | |
return 'New' | |
} else if (!step.getHasCurrentImage()) { | |
return 'Missing' | |
} else { | |
return 'Passed' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment