Last active
March 22, 2019 00:34
-
-
Save jamesasu/4357c60e8992473f2ce8215d5ba21fb6 to your computer and use it in GitHub Desktop.
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
var username = process.env.USERNAME; // See selenium.env | |
var authkey = process.env.PASSWORD; | |
var webdriver = require('selenium-webdriver'), | |
SeleniumServer = require('selenium-webdriver/remote').SeleniumServer, | |
request = require('request'); | |
var remoteHub = "http://" + username + ":" + authkey + "@hub.crossbrowsertesting.com:80/wd/hub"; | |
var browsers = [ | |
{ browserName: 'Chrome', platform: 'Windows 10', version: '64' }, | |
{ browserName: 'Chrome', platform: 'Mac OSX 10.13', version: '71x64' }, | |
{ browserName: 'Safari', platform: 'Mac OSX 10.13', version: '11' }, | |
{ browserName: 'Internet Explorer', platform: 'Windows 8.1', version: '11' }, | |
{ browserName: 'Internet Explorer', platform: 'Windows 7', version: '10' }, | |
{ browserName: 'Edge', platform: 'Windows 10', version: '14' }, | |
{ browserName: 'Firefox', platform: 'Windows 10', version: '60' }, | |
{ browserName: 'Chrome', platform: 'Android', platformVersion: '7.0', deviceName: 'Nexus 6' }, | |
{ browserName: 'Safari', platform: 'iOS', platformVersion: '10.2', deviceName: 'iPad Pro Simulator' } | |
]; | |
// var browsers = [ | |
// { browserName: 'Internet Explorer', platform: 'Windows 8.1', version: '11' }, | |
// { browserName: 'Internet Explorer', platform: 'Windows 7', version: '10' }, | |
// { browserName: 'Internet Explorer', platform: 'Windows 7', version: '9' }, | |
// { browserName: 'Safari', platform: 'Mac OSX 10.13', version: '11' } | |
// ]; | |
// var browsers = [ | |
// { browserName: 'Internet Explorer', platform: 'Windows 7', version: '10' } | |
// ]; | |
function selectByVisibleText(select, textDesired) { | |
select.findElements(webdriver.By.tagName('option')) | |
.then(options => { | |
options.map(option => { | |
option.getText().then(text => { | |
if (text == textDesired) | |
option.click(); | |
}); | |
}); | |
}); | |
} | |
var flows = browsers.map(function(browser) { | |
var caps = { | |
name : 'SU QLD Staging: Donate Once-Off CC', | |
browserName : browser.browserName, | |
username : username, | |
password : authkey | |
}; | |
// Record video??? | |
// caps.record_video = true; | |
if (browser.platform == 'Android' || browser.platform == 'iOS') { | |
caps.platformName = browser.platform; | |
caps.plaformVersion = browser.platformVersion; | |
caps.deviceName = browser.deviceName; | |
} else { | |
caps.platform = browser.platform; | |
caps.version = browser.version; | |
caps.screen_resolution = browser.screen_resolution; | |
} | |
async function donateOnceOffCC(){ | |
try { | |
var driver = new webdriver.Builder() | |
.usingServer(remoteHub) | |
.withCapabilities(caps) | |
.build(); | |
var sessionId; | |
await driver.getSession().then(function(session){ | |
sessionId = session.id_; //need for API calls | |
console.log('Session ID: ', sessionId); | |
console.log('See your test run at: https://app.crossbrowsertesting.com/selenium/' + sessionId) | |
}); | |
await driver.get('https://staging.suqld.org.au/fundraise-new/'); | |
// Wait for page to load | |
await driver.wait(webdriver.until.elementLocated(webdriver.By.css('label[for="custom-amount"]')), 20000); | |
var other = await driver.findElement(webdriver.By.css('label[for="custom-amount"]')); | |
await other.click(); | |
var amount = await driver.findElement(webdriver.By.id('pdwp_custom_amount')); | |
await amount.sendKeys("2"); | |
var continue1 = await driver.findElement(webdriver.By.id('pdwp-cart-cont-btn')); | |
await continue1.click(); | |
// Wait for page to load | |
await driver.wait(webdriver.until.elementLocated(webdriver.By.css(".pdwp-cart-donation-button")), 20000); | |
// Check that we made it to the Cart page: | |
await driver.getTitle().then(function(title) { | |
console.log("The title is: " + title); | |
if (title !== ("Cart – Scripture Union Queensland")) { | |
throw Error('Unexpected title: ' + title); | |
} | |
}); | |
var continue2 = await driver.findElement(webdriver.By.css('.pdwp-cart-donation-button > a.button')); | |
await continue2.click(); | |
// Wait for page to load | |
await driver.wait(webdriver.until.elementLocated(webdriver.By.id("donor_title")), 20000); | |
// Check that we made it to the Checkout page: | |
await driver.getTitle().then(function(title) { | |
console.log("The title is: " + title); | |
if (title !== ("Checkout – Scripture Union Queensland")) { | |
throw Error('Unexpected title: ' + title); | |
} | |
}); | |
var salutation = await driver.findElement(webdriver.By.id('donor_title')); | |
await selectByVisibleText(salutation, "Mr."); | |
var first_name = await driver.findElement(webdriver.By.id('donor_first_name')); | |
await first_name.sendKeys("Test"); | |
var last_name = await driver.findElement(webdriver.By.id('donor_last_name')); | |
await last_name.sendKeys("Selenium"); | |
var email = await driver.findElement(webdriver.By.id('donor_email')); | |
await email.sendKeys("[email protected]"); | |
var phone = await driver.findElement(webdriver.By.id('donor_phone')); | |
await phone.sendKeys("0404123456"); | |
var address = await driver.findElement(webdriver.By.id('donor_address_harmony')); | |
await address.sendKeys("126 BARRY PDE, FORTITUDE VALLEY QLD 4006"); | |
await driver.wait(webdriver.until.elementLocated(webdriver.By.css(".ui-autocomplete > li:first-child")), 10000); | |
var address_select = await driver.findElement(webdriver.By.css('.ui-autocomplete > li:first-child')); | |
await address_select.click(); | |
var gateway = await driver.findElement(webdriver.By.css('label[for="nab_a157F000000QvSDQA0"]')); | |
await gateway.click(); | |
// Card details. | |
await driver.wait(webdriver.until.elementLocated(webdriver.By.id("nab-card-details")), 20000); | |
await driver.wait(webdriver.until.elementLocated(webdriver.By.css("iframe.gw-proxy-number")), 20000); | |
var number_frame = await driver.findElement(webdriver.By.css("iframe.gw-proxy-number")); | |
await driver.switchTo().frame(number_frame); | |
var cardnum = await driver.findElement(webdriver.By.css('input[type="tel"]')); | |
cardnum.click(); | |
await cardnum.sendKeys("4005550000000019"); | |
await driver.switchTo().defaultContent(); | |
var expiry_month = await driver.findElement(webdriver.By.id('nab_expiry_month')); | |
await selectByVisibleText(expiry_month, "05"); | |
var expiry_year = await driver.findElement(webdriver.By.id('nab_expiry_year')); | |
await selectByVisibleText(expiry_year, "2021"); | |
var cardname = await driver.findElement(webdriver.By.id('nab_name_on_card')); | |
await cardname.sendKeys("Test Selenium"); | |
await driver.wait(webdriver.until.elementLocated(webdriver.By.css(".gw-proxy-securityCode")), 20000); | |
var ccv_frame = await driver.findElement(webdriver.By.css(".gw-proxy-securityCode")); | |
await driver.switchTo().frame(ccv_frame); | |
var cardccv = await driver.findElement(webdriver.By.css('input[type="tel"]')); | |
await cardccv.sendKeys("100"); | |
await driver.switchTo().defaultContent(); | |
var submit = await driver.findElement(webdriver.By.id('pdwp-btn')); | |
await submit.click(); | |
// Wait for page to load | |
await driver.wait(webdriver.until.elementLocated(webdriver.By.css(".pronto-donation-success-main-container")), 10000); | |
// Check that we made it to the Thank You page: | |
await driver.getTitle().then(function(title) { | |
console.log("The title is: " + title); | |
if (title !== ("Thank You – Pronto Donation WPPlugin – Scripture Union Queensland")) { | |
throw Error('Unexpected title: ' + title); | |
} | |
}); | |
await driver.takeSnapshot(sessionId); | |
await driver.quit(); | |
setScore(sessionId, 'pass'); | |
} | |
catch(err) { | |
console.error('Exception!\n', err.stack, '\n\n---\n', caps, '\n\n\n\n'); | |
await driver.quit(); | |
setScore(sessionId, 'fail'); | |
} | |
} | |
donateOnceOffCC(); | |
// Set the result to 'pass' or 'fail' | |
function setScore(sessionId, score){ | |
return new Promise((resolve, fulfill)=> { | |
var result = { error: false, message: null } | |
if (sessionId){ | |
request({ | |
method: 'PUT', | |
uri: 'https://crossbrowsertesting.com/api/v3/selenium/' + sessionId, | |
body: {'action': 'set_score', 'score': score }, | |
json: true | |
}, | |
function(error, response, body) { | |
if (error) { | |
result.error = true; | |
result.message = error; | |
} | |
else if (response.statusCode !== 200){ | |
result.error = true; | |
result.message = body; | |
} | |
else{ | |
result.error = false; | |
result.message = 'success'; | |
} | |
}) | |
.auth(username, authkey); | |
} | |
else{ | |
result.error = true; | |
result.message = 'Session Id was not defined'; | |
deferred.fulfill(result); | |
} | |
result.error ? fulfill('Fail') : resolve('Pass'); | |
}); | |
} | |
//Call API to get a snapshot | |
webdriver.WebDriver.prototype.takeSnapshot = function(sessionId) { | |
return new Promise((resolve, fulfill)=> { | |
var result = { error: false, message: null } | |
if (sessionId){ | |
request.post( | |
'https://crossbrowsertesting.com/api/v3/selenium/' + sessionId + '/snapshots', | |
function(error, response, body) { | |
if (error) { | |
result.error = true; | |
result.message = error; | |
} | |
else if (response.statusCode !== 200){ | |
result.error = true; | |
result.message = body; | |
} | |
else{ | |
result.error = false; | |
result.message = 'success'; | |
} | |
} | |
) | |
.auth(username,authkey); | |
} | |
else{ | |
result.error = true; | |
result.message = 'Session Id was not defined'; | |
} | |
result.error ? fulfill('Fail') : resolve('Pass'); //never call reject as we don't need this to actually stop the test | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment