Last active
December 5, 2018 01:57
-
-
Save richardfriedman/167e22476af78fd1cf080aaf34bf0c4c to your computer and use it in GitHub Desktop.
Example RedLine13 WebDriver Test
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
var redline = require( 'redline13-webdriver' ); | |
var browser = redline.loadBrowser('chrome'); | |
var By = redline.webdriver.By; | |
var until = redline.webdriver.until; | |
goto( "https://www.runsignup.com", "RunSignUp" ); | |
sendKeys(By.name("name"),"scott coffee"); | |
clickToTitle(By.xpath("/html/body/div[4]/section[1]/div/div[2]/div/form/div/button"), "Find a Race") | |
clickToTitle(By.xpath("/html/body/div[3]/section[2]/div/div[4]/ul/li[1]/a/span[2]"), "Scott Coffee Moorestown Rotary 8K") | |
clickToTitle( By.linkText( "Results" ), "Scott Coffee Moorestown Rotary 8K Results" ); | |
sendKeys(By.xpath('//*[@id="resultsSearch"]'),"stephen"); | |
redline.snap( "final.png" ); | |
browser.quit(); | |
var defaultWait = 4000; | |
/** | |
* Wraps asserting title. | |
*/ | |
function goto( url, title ){ | |
browser.get( url ); | |
browser.wait( until.titleIs(title), defaultWait ); | |
} | |
/** | |
* Find Element, Click, Wait for Title. | |
*/ | |
function clickToTitle( button, title ){ | |
browser.sleep( 1000 ); | |
browser.wait( until.elementLocated( button ), defaultWait ); | |
browser.findElement( button ).click(); | |
browser.wait( until.titleIs(title), defaultWait ); | |
browser.sleep( Math.floor( Math.random() * defaultWait ) ); | |
} | |
/** | |
* Find Element, Click, Wait for Another Element on the Page. | |
*/ | |
function clickToElement( button, target ){ | |
browser.sleep( 1000 ); | |
browser.wait( until.elementLocated( button ), defaultWait ); | |
browser.wait( until.elementIsVisible( browser.findElement(button) ), defaultWait ); | |
browser.findElement( button ).click(); | |
browser.wait( until.elementLocated( target ), defaultWait ); | |
browser.sleep( Math.floor( Math.random() * defaultWait ) ); | |
} | |
/** | |
* Helper looks for close button and waits for pic (via close button going away) to go away. | |
*/ | |
function clickToHide( close, hide, msg ){ | |
browser.sleep( 1000 ); | |
var hider = browser.findElement(hide); | |
browser.wait( until.elementLocated( close ), defaultWait ).then( function(){console.log("FOUND CLOSE:" + msg);}); | |
browser.findElement( close ).click().then(function(){console.log("CLICKED CLOSE:" + msg);} ); | |
browser.wait( until.elementIsNotVisible( hider ), defaultWait ).then( | |
function(){console.log("HIDDEN:" + msg);}, | |
function(){ | |
console.log("RETRY:" + msg); | |
browser.findElement( close ).click().then(function(){console.log("CLICKED CLOSE:" + msg);} ); | |
browser.wait( until.elementIsNotVisible( hider ), defaultWait ) | |
} | |
); | |
// browser.wait( until.stalenessOf( closer ), defaultWait ); | |
browser.sleep( Math.floor( defaultWait ) ); | |
} | |
/** | |
* Helper, just a click but for download. | |
*/ | |
function clickToDownload( button, target ){ | |
browser.wait( until.elementLocated( button ), defaultWait ); | |
browser.findElement( button ).click(); | |
browser.wait( until.elementLocated( target ), defaultWait ); | |
browser.sleep( Math.floor( Math.random() * defaultWait ) ); | |
} | |
/** | |
* Clear element and put in text. | |
*/ | |
function sendKeys( element, text ){ | |
browser.findElement(element).clear(); | |
browser.findElement(element).sendKeys(text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment