Skip to content

Instantly share code, notes, and snippets.

@richardfriedman
Created January 23, 2017 18:45
Show Gist options
  • Save richardfriedman/3759528c4d51482cd488c3027cda77d5 to your computer and use it in GitHub Desktop.
Save richardfriedman/3759528c4d51482cd488c3027cda77d5 to your computer and use it in GitHub Desktop.
var redline = require( 'redline13-webdriver' );
var browser = redline.loadBrowser('phantomjs');
var By = redline.webdriver.By;
var until = redline.webdriver.until;
goto( "https://www.runsignup.com", "RunSignUp" );
clickToTitle( By.linkText( "RACES" ), "Search Races" );
sendKeys(By.name("name"),"scott coffee");
clickToTitle(By.xpath("//input[@value='Search']"), "Search Races")
clickToTitle(By.xpath("//div[@id='widgetWidth']/div[3]/ul/li[3]/div[2]/div/div/h2/a/span"), "Scott Coffee Moorestown Rotary 8K Race")
clickToTitle( By.linkText( "Results" ), "Scott Coffee Moorestown Rotary 8K Race Results" );
sendKeys(By.id("resultsSearch"),"stephen");
clickToElement(By.id("search"),By.linkText("Stephen Sigwart"));
clickToElement(By.linkText("Stephen Sigwart"),By.css('.bibNum'));
clickToTitle( By.linkText("Photos"), "Scott Coffee Moorestown Rotary 8K Race: RaceDay Photos");
sendKeys(By.id("searchParticipants"),"stephen");
clickToElement(By.id("search"),By.linkText('VIEW PHOTOS'));
clickToElement(By.linkText('VIEW PHOTOS'), By.linkText("DOWNLOAD"));
clickToElement(By.css("img[alt='Event Image']"), By.css("button.pswp__button.pswp__button--close"));
clickToHide(By.css("button.pswp__button.pswp__button--close"));
clickToElement(By.xpath("(//img[@alt='Event Image'])[2]"), By.css("button.pswp__button.pswp__button--close"));
clickToHide(By.css("button.pswp__button.pswp__button--close"));
clickToElement(By.linkText("BACK TO PHOTOS"), By.css("img.raceday-photos-location-img"));
clickToTitle(By.css("img.raceday-photos-location-img"), "Scott Coffee Moorestown Rotary 8K Race: Finish Line");
clickToElement(By.css("img[alt='Event Image']"), By.css("button.pswp__button.pswp__button--close"));
clickToHide(By.css("button.pswp__button.pswp__button--close"));
// Phantom does not support "Download" links.
// clickToDownload(By.linkText("DOWNLOAD"),By.linkText("Race Info"));
clickToElement(By.linkText("Race Info"),By.xpath("(//a[contains(text(),'Race Info')])[2]"));
clickToTitle(By.xpath("(//a[contains(text(),'Race Info')])[2]"),"Scott Coffee Moorestown Rotary 8K Race");
// redline.snap( "final.png" );
browser.quit();
/**
* Wraps asserting title.
*/
function goto( url, title ){
browser.get( url );
browser.wait( until.titleIs(title), 2000 );
}
/**
* Find Element, Click, Wait for Title.
*/
function clickToTitle( button, title ){
browser.wait( until.elementLocated( button ), 2000 );
browser.findElement( button ).click();
browser.wait( until.titleIs(title), 2000 );
browser.sleep( Math.floor( Math.random() * 2000 ) );
}
/**
* Find Element, Click, Wait for Another Element on the Page.
*/
function clickToElement( button, target ){
browser.wait( until.elementLocated( button ), 2000 );
browser.findElement( button ).click();
browser.wait( until.elementLocated( target ), 2000 );
browser.sleep( Math.floor( Math.random() * 2000 ) );
}
/**
* Helper looks for close button and waits for pic (via close button going away) to go away.
*/
function clickToHide( close ){
browser.wait( until.elementLocated( close ), 2000 );
var closer = browser.findElement( close );
closer.click();
browser.wait( until.elementIsNotVisible( closer ), 2000 );
browser.sleep( Math.floor( Math.random() * 2000 ) );
}
/**
* Helper, just a click but for download.
*/
function clickToDownload( button, target ){
browser.wait( until.elementLocated( button ), 2000 );
browser.findElement( button ).click();
browser.wait( until.elementLocated( target ), 2000 );
browser.sleep( Math.floor( Math.random() * 2000 ) );
}
/**
* 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