nightwatch.js

NightWatch.js - get a list of child WebElements based on relative css locator

你。 提交于 2019-12-05 22:45:33
Hello all NightWatch adopters, I am trying to parse a table with the following format to get a a list of rows and the cell in each rows <tbody> <tr> // 1 row <td>Item A</td> // name <td>John</td> // owner <td>Monday</td> // create date </tr> <tr> // 2 row <td>Item B</td> <td>Mary</td> <td>Tuesday</td> </tr> </tbody> The code now looks like this which calls the function below. browser.elements('css selector', 'tbody tr', getResultsList); Where my function for parsing now looks like this. function getResultsList(rowResults){ // Here we get the correct set of rows console.log(rowResults.length +

How to click a link using link text in nightwatch.js

谁说我不能喝 提交于 2019-12-05 20:28:35
问题 Say I have these elements on my web page. <a href="/dynamic1">One</a> <a href="/dynamic2">Two</a> <a href="/dynamic3">Three</a> I want to click on the link with text Two . How to identify or click that element using the Link Text without any unique attributes like id or class. In .Net I can use driver.findElement(By.linkText("Images")).click(); . What is the equivalent in nightwatch.js 回答1: The locator By.linkText uses an XPath internally. So to click the second link from your example with an

How to use Fake timers with nightwatch.js and sinon.js?

旧巷老猫 提交于 2019-12-05 18:40:35
I'm doing JavaScript e2e test with nightwatch.js, and I want to mock the clock with sinon.js's fake timer http://sinonjs.org/docs/#clock But test stops before finish it, I got the log like below, and doesn't progress anymore. [some test] Test Suite =============================== ✔ Element <body> was visible after 5000 milliseconds. My test code is like below. How can I solve the problem? Thank you. module.exports = { before: function(browser) { clock = sinon.useFakeTimers(new Date(2015, 7, 20).getTime()); }, after: function(browser) { clock.restore(); browser.end(); }, 'some test': function

How can I run Nightwatch tests in a specific order?

旧城冷巷雨未停 提交于 2019-12-05 18:28:06
问题 I have several tests which test the UI and also serve to create data along the way. A separate set of tests rely on this data, meaning that these must run only after the first set have run. I know about running a group of them, or running them with tags, but how can I run them in a specific order? 回答1: Nightwatch will run each test within a particular file in order, so one (naive) solution would be to put every test in the same file, in the order you want them to run. This will get unwieldy

Check if one of divs contains my values in nightwatch

↘锁芯ラ 提交于 2019-12-05 10:54:00
I have problem with testing my webapp with nightwatch.js. I need to iterate over all div elements on the page to check if there is the one who contains all child elements I added before. For example I have: <div className = 'myclass'> <h2> text1 </h2> <h3> second_text1 </h3> </div> <div className = 'myclass'> <h2> text2 </h2> <h3> second_text2 </h3> </div> And I want to check if one of divs contains both: 'text2' and 'second_text2'. I tried to add iter function like here: Assert text value of list of webelements using nightwatch.js but I don't know how to check child elements in this div and

How to debug nightwatch tests in VS Code

百般思念 提交于 2019-12-05 08:28:51
I'm trying to debug nightwatch e2e tests using VS Code. I write my tests using typescript. It can work only when I put a breakpoint in js file, after that it goes to ts file and I can debug it from there. If I put it in ts file of my test - it will never stop and it is written "“Breakpoint ignored because generated code not found”. My source files are compiled using ts compiler to folder /dist/dev/specs/e2e/nightwatch/src. Code from the launch.json "name": "Launch e2e Tests on chrome", "type": "node", "console": "integratedTerminal", "program": "${workspaceRoot}/dist/dev/specs/e2e/nightwatch

watch network with nightwatch

走远了吗. 提交于 2019-12-05 06:57:56
I'm using nightwatch to test the frontend of an application. I'm testing that some buttons are clickable or not. Is it possible with nightwatch, to know if there was a network request made by the click, or more generally, to watch the network. Yes, you can use https://www.npmjs.com/package/nightwatch-xhr in order to watch for Ajax requests from Nightwatch.js. (I'm one of the maintainers) Is it possible with nightwatch, to know if there was a network request made by the click, or more generally, to watch the network. No it is not. You cannot with plain nightwatch. It can be done with browsermob

Nightwatch can't locate element via css id or class selectors

天涯浪子 提交于 2019-12-05 04:06:26
We're using Nightwatch to automate some of our UI testing. Some of the current tests are rather brittle, mostly having to do with weird CSS selectors, and I'm trying to simplify them. But some of the simple CSS selectors that I would expect to work are, well, not. I'm trying to find this deeply nested <a> tag: <a class="btn btn-quote btn-crm" href="/crm/" id="btnEndSession" style="display: inline-block;">End Session</a> Here's a bit of code that's working: .waitForElementVisible('#quoteSummary > div > div > div > div > a:nth-child(2)', 1000) .click('#quoteSummary > div > div > div > div > a

Nightwatch: Better way than `.pause(1000)` to avoid brittle tests?

偶尔善良 提交于 2019-12-05 01:07:19
Is .pause(1000) really the best-practice there is to wait for form submission? I'm looking for a way to reliably submit a form without having to know details about the page appearing as a result of the form submission. The example from the home page uses .pause(1000) to wait for form submissions, and ironically doesn't work any longer, but this version with a modified css-selector version does: module.exports = { 'Demo test Google' : function (client) { client .url('http://www.google.com') .waitForElementVisible('body', 1000) .assert.title('Google') .assert.visible('input[type=text]')

nightwatch custom command callback

别来无恙 提交于 2019-12-04 15:51:46
I'm trying to create a custom command in nightwatch that runs a query on a Postgres database and returns the result. The query runs just fine and outputs the result to the console but then the execution of the test stops. I don't understand how callbacks work. How can I fix this custom command? exports.command = function(sql, callback) { var self = this; var pg = require('pg'); var conString = self.globals.testinfo.connectionString; var db = new pg.Client(conString); db.connect(function(err) { if(err) { console.error('could not connect', err); } else { db.query(sql, function(err, result) { if