diff --git a/test/acceptance/Driver.js b/test/acceptance/Driver.js index f502d35f8..c9d519c65 100644 --- a/test/acceptance/Driver.js +++ b/test/acceptance/Driver.js @@ -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 + // }) }) } diff --git a/test/acceptance/dragdrop.spec.js b/test/acceptance/dragdrop.spec.js index a6e921d21..4833aa8ab 100644 --- a/test/acceptance/dragdrop.spec.js +++ b/test/acceptance/dragdrop.spec.js @@ -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 elements’s 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() - }) -}) + }) +} diff --git a/test/acceptance/i18n.spec.js b/test/acceptance/i18n.spec.js index 43648d9b6..290259b84 100644 --- a/test/acceptance/i18n.spec.js +++ b/test/acceptance/i18n.spec.js @@ -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() - }) -}) + }) +} diff --git a/test/acceptance/index.js b/test/acceptance/index.js index 3fb4d425f..186fce242 100644 --- a/test/acceptance/index.js +++ b/test/acceptance/index.js @@ -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 — didn’t 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) + }) +} diff --git a/test/acceptance/old_i18n.spec.js b/test/acceptance/old_i18n.spec.js new file mode 100644 index 000000000..43648d9b6 --- /dev/null +++ b/test/acceptance/old_i18n.spec.js @@ -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() + }) +}) diff --git a/test/acceptance/saucelabs-dummy.spec.js b/test/acceptance/saucelabs-dummy.spec.js new file mode 100644 index 000000000..e7ce39656 --- /dev/null +++ b/test/acceptance/saucelabs-dummy.spec.js @@ -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)