Skip to content

Instantly share code, notes, and snippets.

@heyseus1
Created November 28, 2018 17:14
Show Gist options
  • Save heyseus1/b12354397b4bb88897777765da00419c to your computer and use it in GitHub Desktop.
Save heyseus1/b12354397b4bb88897777765da00419c to your computer and use it in GitHub Desktop.
/* globals $driver $browser */
var request = require('request')
function elementIsPresent (ele) {
$browser.findElements(ele).then(function (found) {
return found.length > 0
})
}
function performBrowserClickTest (path) {
return $browser.findElement($driver.By.xpath(path)).click()
}
function performIsPresentTest (path) {
const isPresent = elementIsPresent($driver.By.xpath(path))
return isPresent
}
// Dummy request necessary to return data to Synthetics
$browser.get('https://www.kqed.org/donate/gateway.jsp')
request
.get('https://www.kqed.org/donate/gateway.jsp')
.on('response',
function (response) {
console.log('statusCode:', response.statusCode)
}
)
$browser.get('https://www.kqed.org/donate/gateway.jsp').then(() => (
// Click the "Ongoing Monthly Donation"
console.log(performBrowserClickTest("//*[@id='donate-gateway']/li[1]/a/h2"))
)).then(() => (
// check for text "Donate without a Gift"
performIsPresentTest("//*[@id='main']/div[1]/h3")
)).then(() => (
// click "15$/month"
console.log(performBrowserClickTest("//*[@id='main']/div[1]/div[1]/div[1]/p[3]/a[1]"))
)).then(() => (
// check for text "Payment Method"
performIsPresentTest("//*[@id='pledge-form']/div[3]/div[1]/div[1]")
)).then(() => (
// click "donate"
console.log(performBrowserClickTest("//*[@id='kqed-hd-tools']/a"))
)).then(() => (
// click "One-Time Donation"
console.log(performBrowserClickTest("//*[@id='donate-gateway']/li[2]/a/h2"))
)).then(() => (
// check for text "Donate without a Gift"
performIsPresentTest("//*[@id='main']/div[1]/h3")
)).then(() => (
// click "$40"
console.log(performBrowserClickTest("//*[@id='main']/div[1]/div[1]/div[1]/p[3]/a[1]"))
)).then(() => (
// check for text "Payment Method"
performIsPresentTest("//*[@id='pledge-form']/div[3]/div[1]/div[1]")
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment