Skip to content

Instantly share code, notes, and snippets.

@nghiadhd

nghiadhd/wd.js Secret

Created December 6, 2016 07:27
Show Gist options
  • Save nghiadhd/8388fe2b2e9e1917298e0b9d4d52d952 to your computer and use it in GitHub Desktop.
Save nghiadhd/8388fe2b2e9e1917298e0b9d4d52d952 to your computer and use it in GitHub Desktop.
import 'babel-polyfill'
import wd from 'wd'
import async from 'async'
import {assert} from 'chai'
import faker from 'faker'
import moment from 'moment'
const boundLog = console.log.bind(console)
const server = {
host: 'localhost',
port: 4723
}
const platformName = process.env.PLATFORM === 'iOS'
? "iOS"
: "Android"
const desiredCaps = {
"udid": process.env.UDID,
"browserName": platformName === 'iOS' ? 'safari' : 'chrome',
"deviceName": 'Galaxy',
"deviceOrientation": "portrait"
}
const timeOut = 60000
const loopCount = process.env.RUN_LOOP || 20
describe(`Run test`, async () => {
let i = 0
let startedAt, endedAt
let duration = 0
let driver
const expectedDuration = 3 //minutes
const test = async () => {
it(`wd ${i}`, async () => {
try {
driver = wd.promiseChainRemote(server)
driver
.on('status', boundLog)
.on('command', boundLog)
.on('http', boundLog)
startedAt = moment.utc()
await driver
.init(desiredCaps)
.get('http://automationpractice.com/index.php?controller=authentication&back=my-account')
.waitForElementById('email_create', timeOut)
.elementById('email_create').type(faker.internet.email())
.elementById('SubmitCreate').click()
.waitForElementById('id_gender1', timeOut)
.elementById('id_gender1').click()
do {
await driver // eslint-disable-line babel/no-await-in-loop
.waitForElementById('customer_firstname', timeOut)
.elementById('customer_firstname').clear().type(faker.name.firstName())
.elementById('customer_lastname').clear().type(faker.name.lastName())
.elementById('passwd').clear().type(faker.internet.password())
endedAt = moment.utc()
duration = endedAt.diff(startedAt, 'minutes')
} while (duration < expectedDuration)
}
finally {
driver && await driver.quit()
}
})
if (i < loopCount - 1) {
i++
await test()
}
}
await test()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment