From c3c6fcd20e12ff2807941649051d3f66f2737914 Mon Sep 17 00:00:00 2001 From: Kim Leung Date: Tue, 17 Oct 2017 08:48:36 -0400 Subject: [PATCH] running tests successfully --- .gitignore | 1 + nightwatch.json | 13 +++++++------ package.json | 5 ++++- selenium-setup.js | 6 ++++++ tests/demo.js | 5 +++-- tests/index.js | 23 +++++++++++++++++++++++ 6 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 selenium-setup.js create mode 100644 tests/index.js diff --git a/.gitignore b/.gitignore index 6785e80..1d30427 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +bin node_modules npm_debug.log Screenshots diff --git a/nightwatch.json b/nightwatch.json index 9f2445b..e45efce 100644 --- a/nightwatch.json +++ b/nightwatch.json @@ -7,12 +7,12 @@ "globals_path" : "", "selenium" : { - "start_process" : false, - "server_path" : "", - "log_path" : "", + "start_process" : true, + "server_path" : "./bin/selenium.jar", + "log_path" : "./reports", "port" : 4444, "cli_args" : { - "webdriver.chrome.driver" : "", + "webdriver.chrome.driver" : "./bin/chromedriver", "webdriver.gecko.driver" : "", "webdriver.edge.driver" : "" } @@ -25,11 +25,12 @@ "selenium_host" : "localhost", "silent": true, "screenshots" : { - "enabled" : false, + "enabled" : true, "path" : "" }, "desiredCapabilities": { - "browserName": "chrome" + "browserName": "chrome", + "javascriptEnabled": true } }, diff --git a/package.json b/package.json index 06010b5..9d5311c 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "author": "Kalefive", "main": "server.js", "scripts": { - "start": "node server.js" + "start": "node server.js", + "test": "nightwatch", + "e2e:setup": "node selenium-setup" }, "dependencies": { "blink-diff": "^1.0.13", @@ -15,6 +17,7 @@ "geckodriver": "^1.9.0", "nightwatch": "^0.9.16", "node-inspector": "^1.1.1", + "selenium-download": "^2.0.10", "selenium-webdriver": "^3.5.0" } } diff --git a/selenium-setup.js b/selenium-setup.js new file mode 100644 index 0000000..a2e230c --- /dev/null +++ b/selenium-setup.js @@ -0,0 +1,6 @@ +const selenium = require('selenium-download'); + +selenium.ensure(__dirname + '/bin', function (error) { + if (error) console.error(error.stack); + process.exit(0); +}); diff --git a/tests/demo.js b/tests/demo.js index 2a70bbc..fe4c971 100644 --- a/tests/demo.js +++ b/tests/demo.js @@ -4,8 +4,9 @@ module.exports = { .url('http://www.google.com') .waitForElementVisible('body', 1000) .setValue('input[type=text]', 'nightwatch') - .waitForElementVisible('button[name=btnG]', 1000) - .click('button[name=btnG]') + .waitForElementVisible('input[value="Google Search"]', 1000) + .saveScreenshot('./reports/homepage.png') + .click('input[value="Google Search"]') .pause(1000) .assert.containsText('#main', 'Night Watch') .end(); diff --git a/tests/index.js b/tests/index.js new file mode 100644 index 0000000..e749f52 --- /dev/null +++ b/tests/index.js @@ -0,0 +1,23 @@ +module.exports = { + + //Each "export" counts as one test case + 'index': browser => { + + //We direct our browser to the google homepage, and wait for it to load + browser.url('http://google.com') + .waitForElementVisible('body', 1000) + + // We then test to see that the "Search" button is visible + browser.assert.elementPresent('input[value="Google Search"]') + + //We then fill the search bar with the word "Nightwatch" + browser.setValue('#lst-ib', 'Nightwatch') + + //then, we click on "Search", and wait for the search results to appear + browser.click('input[value="Google Search"]') + .waitForElementVisible('#resultStats', 1000) + + //Once thats done, we close the browser + browser.end() + } +}