Make acceptance tests run on Local & Remote environments

Depending on whether or not process.env.ACCESS_KEY is supplied
This commit is contained in:
Artur Paikin 2016-04-29 00:41:09 -04:00
parent cee0b16668
commit 2e3eec65da
6 changed files with 230 additions and 78 deletions

View file

@ -13,21 +13,21 @@ function collectErrors (driver) {
chalk.magenta(uppyLog)
].join(' '))
return driver.executeScript('return window.JSErrorCollector_errors.pump()')
.then(function (errors) {
if (!errors || !errors.length) {
return
}
errors.forEach(function (error) {
console.error([
'[browser-error]',
chalk.magenta(error.sourceName),
chalk.dim('#' + error.lineNumber),
chalk.red(error.errorMessage)
].join(' '))
})
return
})
// return driver.executeScript('return window.JSErrorCollector_errors.pump()')
// .then(function (errors) {
// if (!errors || !errors.length) {
// return
// }
// errors.forEach(function (error) {
// console.error([
// '[browser-error]',
// chalk.magenta(error.sourceName),
// chalk.dim('#' + error.lineNumber),
// chalk.red(error.errorMessage)
// ].join(' '))
// })
// return
// })
})
}

View file

@ -1,52 +1,63 @@
var test = require('tape')
var path = require('path')
var webdriver = require('selenium-webdriver')
var chalk = require('chalk')
var By = webdriver.By
var Driver = require('./Driver')
var By = Driver.By
var collectErrors = Driver.collectErrors
test('dragdrop: make sure DragDrop accepts and uploads 1 file via input', function (t) {
t.plan(1)
module.exports = function (driver, platform, host) {
test('dragdrop: make sure DragDrop accepts and uploads 1 file via input ' +
chalk.underline.yellow('[' +
platform.os + ' ' +
platform.browser + ' ' +
platform.version +
']'),
function (t) {
t.plan(1)
var driver = Driver.setDriver()
// Go to the example URL
driver.get(host + '/examples/dragdrop/')
// Go to the example URL
driver.get('http://localhost:4000/examples/dragdrop/')
// Make file input “visible”
driver.executeScript('document.querySelector(".UppyDragDrop-One .UppyDragDrop-input").style.opacity = 1')
// Find input by css selector & pass absolute image path to it
driver
.findElement(By.css('.UppyDragDrop-One .UppyDragDrop-input'))
.sendKeys(path.join(__dirname, 'image.jpg'))
// Find input by css selector & pass absolute image path to it
driver
.findElement(By.css('.UppyDragDrop-One .UppyDragDrop-input'))
.sendKeys(path.join(__dirname, 'image.jpg'))
// Get console elementss value, then check if it has “Download” there somewhere,
// if it does, then test passes
function isUploaded () {
// return driver.findElement(By.id('console-log'))
// .getAttribute('value')
// .then(function (value) {
// var isFileUploaded = value.indexOf('Download image.jpg') !== -1
// return isFileUploaded
// })
function isUploaded () {
// return driver.findElement(By.id('console-log'))
// .getAttribute('value')
// .then(function (value) {
// var isFileUploaded = value.indexOf('Download image.jpg') !== -1
// return isFileUploaded
// })
// .getText() only work on visible elements, so we use .getAttribute('textContent'), go figure
// http://stackoverflow.com/questions/21994261/gettext-not-working-on-a-select-from-dropdown
return driver.findElement(By.css('.UppyDragDrop-One-Progress .UppyProgressBar-percentage'))
.getAttribute('textContent')
.then(function (value) {
var progress = parseInt(value)
var isFileUploaded = progress === 100
return isFileUploaded
// .getText() only work on visible elements, so we use .getAttribute('textContent'), go figure
// http://stackoverflow.com/questions/21994261/gettext-not-working-on-a-select-from-dropdown
return driver.findElement(By.css('.UppyDragDrop-One-Progress .UppyProgressBar-percentage'))
.getAttribute('textContent')
.then(function (value) {
var progress = parseInt(value)
var isFileUploaded = progress === 100
return isFileUploaded
})
}
driver.wait(isUploaded, 15000, 'File image.jpg should be uploaded within 15 seconds')
.then(function (result) {
collectErrors(driver).then(function () {
t.equal(result, true)
driver.quit()
})
})
}
driver.wait(isUploaded, 15000, 'File image.jpg should be uploaded within 15 seconds')
.then(function (result) {
collectErrors(driver).then(function () {
t.equal(result, true)
driver.quit()
.catch(function (err) {
collectErrors(driver).then(function () {
t.fail(err)
driver.quit()
})
})
})
.catch(function (err) {
t.fail(err)
driver.quit()
})
})
})
}

View file

@ -1,32 +1,42 @@
var test = require('tape')
var chalk = require('chalk')
var webdriver = require('selenium-webdriver')
var By = webdriver.By
var Driver = require('./Driver')
var By = Driver.By
var collectErrors = Driver.collectErrors
test('i18n: make sure Uppy loads with Russian language pack', function (t) {
t.plan(1)
module.exports = function (driver, platform, host) {
test('i18n: make sure Uppy loads with Russian language pack ' +
chalk.underline.yellow('[' +
platform.os + ' ' +
platform.browser + ' ' +
platform.version +
']'),
function (t) {
t.plan(1)
var driver = Driver.setDriver()
function findLabelTextElement () {
return driver.findElements(By.css('.UppyDragDrop-label')).then(function (result) {
return result[0]
})
}
function findLabelTextElement () {
return driver.findElements(By.css('.UppyDragDrop-label')).then(function (result) {
return result[0]
})
}
driver.get(host + '/examples/i18n')
driver.get('http://localhost:4000/examples/i18n')
driver.wait(findLabelTextElement, 8000, 'Uppy should load within 8 seconds')
.then(function (element) {
element.getText().then(function (value) {
driver.wait(findLabelTextElement, 8000, 'Uppy should load within 8 seconds')
.then(function (element) {
element.getText().then(function (value) {
collectErrors(driver).then(function () {
t.equal(value, 'Выберите файл или перенесите его сюда')
driver.quit()
})
})
})
.catch(function (err) {
collectErrors(driver).then(function () {
t.equal(value, 'Выберите файл или перенесите его сюда')
t.fail(err)
driver.quit()
})
})
})
.catch(function (err) {
t.fail(err)
driver.quit()
})
})
})
}

View file

@ -1,5 +1,7 @@
// Docs aren't that great to find. Mostly JAVA based. Here are few helpful resources:
// - https://www.browserstack.com/automate/node#testing-frameworks
// - http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/firefox/index_exports_Driver.html
// - https://github.com/SeleniumHQ/selenium/blob/c10e8a955883f004452cdde18096d70738397788/javascript/node/selenium-webdriver/test/upload_test.js
//
// - https://github.com/SeleniumHQ/selenium/wiki/WebDriverJs
// - http://seleniumhq.github.io/selenium/docs/api/javascript/
@ -8,5 +10,65 @@
// - http://selenium.googlecode.com/git/docs/api/javascript/class_webdriver_WebElement.html
require('babel-register')
require('./i18n.spec.js')
require('./dragdrop.spec.js')
var webdriver = require('selenium-webdriver')
var remote = require('selenium-webdriver/remote')
var username = process.env.USERNAME
var accessKey = process.env.ACCESS_KEY
// if accessKey is supplied as env variable, this is a remote Saucelabs test
var isRemoteTest = accessKey ? true : ''
var host = isRemoteTest ? 'http://uppi.io' : 'http://localhost:4000'
// FYI: old Chrome on Windows XP,
// Opera 12 on Linux — didnt pass
var platforms = [
// { browser: 'Opera', version: '12', os: 'Linux' },
{ browser: 'firefox', version: '34.0', os: 'Windows 7' },
{ browser: 'chrome', version: '48.0', os: 'Windows XP' }
]
var tests = [
require('./i18n.spec.js'),
require('./dragdrop.spec.js')
]
function buildDriver (platform) {
var driver
if (isRemoteTest) {
driver = new webdriver
.Builder()
.withCapabilities({
'browserName': platform.browser,
'platform': platform.os,
'version': platform.version,
'username': username,
'accessKey': accessKey
})
.usingServer('http://' + username + ':' + accessKey +
'@ondemand.saucelabs.com:80/wd/hub')
.build()
driver.setFileDetector(new remote.FileDetector())
} else {
driver = new webdriver
.Builder()
.forBrowser('firefox')
.build()
}
return driver
}
if (isRemoteTest) {
platforms.forEach(function (platform) {
tests.forEach(function (test) {
var driver = buildDriver(platform)
test(driver, platform, host)
})
})
} else {
tests.forEach(function (test) {
var driver = buildDriver()
test(driver, { browser: 'Firefox', version: 'Version', os: 'Local' }, host)
})
}

View file

@ -0,0 +1,32 @@
var test = require('tape')
var Driver = require('./Driver')
var By = Driver.By
var collectErrors = Driver.collectErrors
test('i18n: make sure Uppy loads with Russian language pack', function (t) {
t.plan(1)
var driver = Driver.setDriver()
function findLabelTextElement () {
return driver.findElements(By.css('.UppyDragDrop-label')).then(function (result) {
return result[0]
})
}
driver.get('http://localhost:4000/examples/i18n')
driver.wait(findLabelTextElement, 8000, 'Uppy should load within 8 seconds')
.then(function (element) {
element.getText().then(function (value) {
collectErrors(driver).then(function () {
t.equal(value, 'Выберите файл или перенесите его сюда')
driver.quit()
})
})
})
.catch(function (err) {
t.fail(err)
driver.quit()
})
})

View file

@ -0,0 +1,37 @@
var webdriver = require('selenium-webdriver')
var remote = require('selenium-webdriver/remote')
var username = process.env.USERNAME
var accessKey = process.env.ACCESS_KEY
var platform = { browser: 'firefox', version: '34.0', os: 'Windows 7' }
function buildDriver (platform) {
var driver = new webdriver
.Builder()
.withCapabilities({
'browserName': platform.browser,
'platform': platform.os,
'version': platform.version,
'username': username,
'accessKey': accessKey
})
.usingServer('http://' + username + ':' + accessKey +
'@ondemand.saucelabs.com:80/wd/hub')
.build()
driver.setFileDetector(new remote.FileDetector())
return driver
}
function runTest (driver, platform) {
console.log('Running dummy test in ' + platform.browser + ' on ' + platform.os)
driver.get('http://ya.ru')
return driver.getTitle().then(function (title) {
console.log('title is: ' + title)
console.log('Finnished running dummy test, I quit!')
driver.quit()
})
}
var driver = buildDriver(platform)
runTest(driver, platform)