dwyl / learn-nightwatch

:last_quarter_moon_with_face: Learn how to use Nightwatch.js to easily & automatically test your web apps in *real* web browsers.
584 stars 214 forks source link

Title element assertion fails. #69

Closed GnrySgtSkitlz closed 7 years ago

GnrySgtSkitlz commented 7 years ago

I have followed the read me instructions and thankyou as they're very clear. However I am finding that when trying to assert that my title equals Home Page I either get a test failed, expected Home Page but got "" or failed, expected Home Page but got "local host".

I think it's a configuration issue as the waitForElementVisible('title') fails but waitForElementPresent('title') succeeds

The chrome window pops up but shows a default page and an alert saying that a testing program is running chrome.

I'll add some code snippets shortly as I'm not at my PC ....Edit.... Test var config = require('../nightwatch.conf.js'); module.exports = { // adapted from: https://git.io/vodU0 'Login Assert': function(browser) { browser .url('https://localhost:5100/Login') .waitForElementPresent('title') .waitForElementVisible('body') //.assert.title('Home Page') .saveScreenshot('LandingScreen.png'); browser.assert.containsText('title', "Home Page") } };

Config //require('env2')('.env'); // optionally store your Evironment Variables in .env const SCREENSHOT_PATH = "./screenshots/"; const BINPATH = './node_modules/nightwatch/bin/';

// we use a nightwatch.conf.js file so we can include comments and helper functions module.exports = { "src_folders": [ "Portal/UIAutomationTests/"// Where you are storing your Nightwatch e2e tests ], "output_folder": "Portal/UIAutomationTestReports", // reports (test outcome) output by nightwatch "selenium": { // downloaded by selenium-download module (see readme) "start_process": true, // tells nightwatch to start/stop the selenium process "server_path": "./node_modules/nightwatch/bin/selenium.jar", "host": "127.0.0.1", "port": 4444, // standard selenium port "cli_args": { // chromedriver is downloaded by selenium-download (see readme) "webdriver.chrome.driver" : "./node_modules/nightwatch/bin/chromedriver" } }, "test_settings": { "default": { "screenshots": { "enabled": true, // if you want to keep screenshots "path": SCREENSHOT_PATH // save screenshots here }, "globals": { "waitForConditionTimeout": 5000 // sometimes internet is slow so wait. }, "desiredCapabilities": { // use Chrome as the default browser for tests "browserName": "chrome" } }, "chrome": { "desiredCapabilities": { "browserName": "chrome", "javascriptEnabled": true // turn off to test progressive enhancement } } } } /**

require('fs').stat(BINPATH + 'selenium.jar', function (err, stat) { // got it? if (err || !stat || stat.size < 1) { require('selenium-download').ensure(BINPATH, function(error) { if (error) throw new Error(error); // no point continuing so exit! console.log('✔ Selenium & Chromedriver downloaded to:', BINPATH); }); } });

function padLeft (count) { // theregister.co.uk/2016/03/23/npm_left_pad_chaos/ return count < 10 ? '0' + count : count.toString(); }

var FILECOUNT = 0; // "global" screenshot file count /**

module.exports.imgpath = imgpath; module.exports.SCREENSHOT_PATH = SCREENSHOT_PATH;

Results Running: Login Assert ✔ Element was present after 76 milliseconds. ✔ Element <body> was visible after 45 milliseconds. ✖ Testing if element <title> contains text: "Home Page". - expected "Home Page" but got: ""</p> <p>Thanks in advance</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/GnrySgtSkitlz"><img src="https://avatars.githubusercontent.com/u/12027272?v=4" />GnrySgtSkitlz</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>So that answer to this is that I was attempting to use HTTPS and not HTTP, looks like either the selenium webdriver or chromedriver doesn't like using secure urls.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/nelsonic"><img src="https://avatars.githubusercontent.com/u/194400?v=4" />nelsonic</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>@GnrySgtSkitlz that's <em>odd</em> could it be that the HTTPS has an <em>unrecognised</em> certificate?</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/GnrySgtSkitlz"><img src="https://avatars.githubusercontent.com/u/12027272?v=4" />GnrySgtSkitlz</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>@nelsonic I will double check, but i don't think its the case. I have a feeling, an I can't remember where I have read it but there is a way to set the chrome arguments. One of the arguments was to do with secure connection...I'll have another look.</p> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>