Skip to content

Instantly share code, notes, and snippets.

@nicolevanderhoeven
Last active February 19, 2018 18:38
Show Gist options
  • Save nicolevanderhoeven/14704133a3630da95eb847cbcc8c9473 to your computer and use it in GitHub Desktop.
Save nicolevanderhoeven/14704133a3630da95eb847cbcc8c9473 to your computer and use it in GitHub Desktop.
Flood Challenge - Flood Chrome script
import { step, TestSettings, Until, By, MouseButtons, Device, Driver } from '@flood/chrome'
import * as assert from 'assert'
export default () => {
step('Challenge Home', async browser => {
//Navigate to homepage.
await browser.visit('https://challenge.flood.io')
//Validate text
let validation = By.visibleText('Ready to take the test?')
await browser.wait(Until.elementIsVisible(validation))
})
step('Step 1', async browser => {
//Click Start button
let startButton = await browser.findElement('.btn-default')
await startButton.click()
//Validate text
let validation = By.visibleText('Step 2')
await browser.wait(Until.elementIsVisible(validation))
})
step('Step 2', async browser => {
//Select age.
await browser.selectByValue('#challenger_age','32')
//Click Next.
let nextButton = await browser.findElement('.btn')
await nextButton.click()
//Validate text
let validation = By.visibleText('Step 3')
await browser.wait(Until.elementIsVisible(validation))
})
step('Step 3', async browser => {
//Get all order values.
let orderLabels = await browser.findElements(By.xpath('//label[@class="collection_radio_buttons"]'))
let orderValues = await Promise.all(orderLabels.map(label => label.text()))
console.log('orderValues = ' + orderValues)
console.log('length of array = ' + orderValues.length)
let orderValuesNumArray = orderValues.map(Number)
console.log('orderValuesNumArray = ' + orderValuesNumArray.toString())
//Sort number array into ascending order
orderValuesNumArray.sort(function(a,b){
return a - b
})
console.log('orderValuesNumArray sorted = ' + orderValuesNumArray.toString())
var largestValue = orderValuesNumArray[orderValuesNumArray.length-1].toString()
console.log('largestValue = ' + largestValue)
//Select radio button with the highest orderValues
var strXPath = 'descendant::input[@class="radio_buttons optional" and @id = //label[text() = "' + largestValue + '"]/@for]'
console.log('strXPath = ' + strXPath)
let orderLabelFor = await browser.findElement(By.xpath(strXPath))
await orderLabelFor.click()
//Verify that the radio button has been selected
if (orderLabelFor.isSelected()) {
console.log('radio button is selected')
}
else {
console.log('radio button not selected')
}
//Type the highest value in the text field.
await browser.type(By.id('challenger_largest_order'), largestValue)
//Click the Next button.
let nextButton = await browser.findElement('.btn')
await nextButton.click()
//Validate text
let validation = By.visibleText('Step 4')
await browser.wait(Until.elementIsVisible(validation))
})
step('Step 4', async browser => {
//Click the Next button.
let nextButton = await browser.findElement('.btn')
await nextButton.click()
//Validate text
let validation = By.visibleText('Step 5')
await browser.wait(Until.elementIsVisible(validation))
})
step('Step 5', async browser => {
//Get One Time Token value
let oneTimeToken = await browser.findElements(By.xpath('//*[@id="new_challenger"]/h4/span[2]'))
let oneTimeTokenValue = await Promise.all(oneTimeToken.map(span => span.text()))
console.log('oneTimeTokenValue = ' + oneTimeTokenValue[0])
//Type One Time Token value into text input
await browser.type(By.id('challenger_one_time_token'),oneTimeTokenValue[0])
//Click the Next button.
let nextButton = await browser.findElement('.btn')
await nextButton.click()
//Validate text
let validation = By.visibleText('Hall of Fame')
await browser.wait(Until.elementIsVisible(validation))
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment