Skip to content

Instantly share code, notes, and snippets.

@screenster
screenster / resemble.js
Created May 23, 2018 13:45
Code snippet for a post about image comparison tools: https://screenster.io/image-comparison-tool/
//compare two images
var diff = resemble(newImage).compareTo(originalImage).onComplete(function(comparisonData){
console.log(comparisonData);
});
// additional settings:
// diff.scaleToSameSize() — match the size of the new image to the baseline image;
// diff.ignoreAntialiasing() — ignore anti-aliasing (to minimize false positives);
// diff.ignoreColors() — ignore colors;
@screenster
screenster / content-verification-xpath
Created September 22, 2017 11:52
Content verification sample (On content verification and why it’s important for UI testing)
driver.findElement(By.xpath("//*[contains(text(),'someText')]"));
@screenster
screenster / text-verification-matches
Last active May 23, 2018 13:58
Text verification code sample for the post (https://screenster.io/end-to-end-testing/ )
assertTrue(driver.findElement(By.cssSelector("BODY")).getText().matches("^[\\s\\S]* Your text here\r\n\r\n[\\s\\S]*$"));
@screenster
screenster / selenium-ide-chrome
Last active May 23, 2018 13:34
Snipper for running Selenium IDE on Chrome: https://screenster.io/selenium-ide-chrome/
java -jar selenium-server-standalone-2.43.1.jar -Dwebdriver.chrome.driver=chromedriver.exe
@screenster
screenster / smart-selector-1
Created September 14, 2017 14:08
Smart selector example for a locators tutorial
[
{"nthOfType":1, "tagName":"BODY"}
{"id":"header", "nthOfType":1, "tagName":"DIV"},
{"classes":["header__nav"], "nthOfClass":0, "nthOfType":1, "tagName":"UL"},
{"classes":["nav__item"], "nthOfClass":0, "nthOfType":1, "tagName":"LI"},
{"innerHTML":"Home", "nthOfType":1, "tagName":"A"}
]
@screenster
screenster / nav-list
Created September 14, 2017 14:05
Navigation snippet for "Selenium Locators Tutorial: Types, Best Practices, and many more"
<body>
<div id=“header”>
<ul class=“header__nav nav”>
<li class="nav__item"><a href=“#”>Home</a></li>
<li class="nav__item"><a href=“#”>Blog</a></li>
</ul>
</div>
<div class=“content”>
<div class=“menu-left”>
@screenster
screenster / smart-seletor-1
Last active May 23, 2018 13:55
Example of a smart selector for Selenium Locators Tutorial (https://screenster.io/selenium-alternatives-for-testing-automation/)
[
{"tagName":"HTML"},{"nthOfType":1,"tagName":"BODY"},
{"classes":["content-wrapper"],"nthOfClass":0,"nthOfType":1,"tagName":"DIV"},
{"classes":["menu-left"],"nthOfClass":0,"nthOfType":1,"tagName":"DIV"},
{"classes":["article", “full-width”],"nthOfClass":0,"nthOfType":1,"tagName":"DIV"}
]
@screenster
screenster / menu-item
Last active May 23, 2018 13:57
Code snippet for the Selenium Locators Tutorial (https://screenster.io/selenium-locators-best-practices/)
<body>
<div class=”content-wrapper”>
<div class=”menu-left”>
<div class=”article full-width”>
<p>All work and no play makes Jack a dull boy</p>
</div>
</div>
</div>
</body>
@screenster
screenster / dynamic-id
Created September 14, 2017 13:47
Example of a locator based on a dynamic ID for "Selenium Locators Tutorial: Types, Best Practices, and many more"
<ul id=“navigation-4815162342” class=“nav”>
<!-- list items -->
</ul>
WebElement navigation = browser.findElement(By.xpath(“//ul[contains(@id, ‘navigation’)]”));