From 0bd33d6f00f135abfd2acd1cc981afcfb0a2f0a3 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Sat, 04 May 2019 13:08:27 +0000
Subject: [PATCH] Switch to Nightwatch.js for browser tests
---
/dev/null | 45 ---------------
tests/index.js | 31 ++++++++++
.travis.yml | 9 ++
nightwatch.conf.js | 50 ++++++++++++++++
4 files changed, 88 insertions(+), 47 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 8bb4f98..399c72f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,10 +6,15 @@
- 7.0
- nightly
+addons:
+ firefox: latest
+ chrome: stable
+
before_script:
- 'php -S 127.0.0.1:8080 &'
- 'nvm install stable'
- - 'npm install casperjs'
+ - 'npm install nightwatch selenium-server chromedriver geckodriver'
script:
- - 'node_modules/casperjs/bin/casperjs test tests.js'
+ - 'node_modules/.bin/nightwatch -e chrome-headless'
+ - 'node_modules/.bin/nightwatch -e firefox-headless'
diff --git a/nightwatch.conf.js b/nightwatch.conf.js
new file mode 100644
index 0000000..4fef425
--- /dev/null
+++ b/nightwatch.conf.js
@@ -0,0 +1,50 @@
+var seleniumServer = require('selenium-server');
+var chromedriver = require('chromedriver');
+var geckodriver = require('geckodriver');
+
+module.exports = {
+ src_folders: ['tests'],
+ selenium: {
+ start_process: true,
+ server_path: seleniumServer.path,
+ port: 4444,
+ cli_args: {
+ 'webdriver.chrome.driver': chromedriver.path,
+ 'webdriver.gecko.driver': geckodriver.path,
+ },
+ },
+ test_settings: {
+ 'chrome': {
+ desiredCapabilities: {
+ browserName: 'chrome',
+ },
+ },
+ 'chrome-headless': {
+ desiredCapabilities: {
+ browserName: 'chrome',
+ chromeOptions: {
+ args: [
+ '--headless',
+ '--no-sandbox',
+ '--disable-gpu',
+ ],
+ },
+ },
+ },
+ 'firefox': {
+ desiredCapabilities: {
+ browserName: 'firefox',
+ },
+ },
+ 'firefox-headless': {
+ desiredCapabilities: {
+ browserName: 'firefox',
+ 'moz:firefoxOptions': {
+ args: [
+ '--headless',
+ ],
+ },
+ },
+ },
+ },
+};
diff --git a/tests.js b/tests.js
deleted file mode 100644
index d82b00b..0000000
--- a/tests.js
+++ /dev/null
@@ -1,45 +0,0 @@
-casper.test.begin('Stop name autocompletion', 4, function(test) {
- casper.start('http://127.0.0.1:8080/', function() {
- test.assertTitleMatches(/^TTSS\s/, 'Page title: TTSS...');
- });
-
- var autocomplete_pairs = [
- ['bag', 'Teatr Bagatela'],
- ['d g', 'Dworzec Główny'],
- ['świę', 'Plac Wszystkich Świętych'],
- ];
-
- autocomplete_pairs.forEach(function(value) {
- casper.then(function() {
- this.sendKeys('#stop-name', value[0], {reset: true});
- }).wait(200, function() {
- test.assertSelectorHasText(
- '#stop-name-autocomplete > option',
- value[1],
- 'Autocomplete: ' + value[1]
- );
- });
- });
-
- casper.run(function() {
- test.done();
- });
-});
-
-casper.test.begin('Translation engine', 2, function(test) {
- casper.start('http://127.0.0.1:8080/#!en', function() {
- test.assertTitleMatches(/departures/i, 'Page title: ...departures...');
- });
-
- casper.wait(200, function() {
- test.assertSelectorHasText(
- '[data-translate=header_line]',
- 'Line',
- 'Translation: Linia -> Line'
- );
- });
-
- casper.run(function() {
- test.done();
- });
-});
diff --git a/tests/index.js b/tests/index.js
new file mode 100644
index 0000000..c9827b0
--- /dev/null
+++ b/tests/index.js
@@ -0,0 +1,31 @@
+module.exports = {
+ 'Stop name autocompletion': function(browser) {
+ browser.url('http://127.0.0.1:8080/');
+ browser.getTitle(function(title) {
+ this.assert.ok(title.includes('TTSS'));
+ });
+
+ var autocomplete_pairs = [
+ ['baga', 'Teatr Bagatela'],
+ ['d g', 'Dworzec Główny'],
+ ['świę', 'Plac Wszystkich Świętych'],
+ ['św g', 'Św. Gertrudy'],
+ ['św.g', 'Św. Gertrudy'],
+ ];
+ autocomplete_pairs.forEach(function(value) {
+ browser.clearValue('#stop-name');
+ browser.setValue('#stop-name', value[0]);
+ browser.pause(200);
+ browser.expect.element('#stop-name-autocomplete > option:first-child').to.be.present.before(1000);
+ browser.expect.element('#stop-name-autocomplete > option:first-child').text.to.include(value[1]).before(1000);
+ });
+ },
+ 'Translation engine': function(browser) {
+ browser.url('http://127.0.0.1:8080/#!en');
+ browser.pause(200);
+ browser.getTitle(function(title) {
+ this.assert.ok(title.includes('departures'));
+ });
+ browser.expect.element('[data-translate=header_line]').text.to.include('Line');
+ },
+};
--
Gitblit v1.9.1