nightwatch.js

Loop is not working properly - nightwatch

别来无恙 提交于 2019-12-01 13:21:50
问题 I have this code, I want to go thru all the links available at the bottom of the page. After clicking them I want to make sure the URL opened is the correct one. I think the the recursive calls are done too early. Another issue is how can I do to tell that link belongs to certain URL. function links(browser, total_links) { if (total_links <= 0) { browser.end(); return; } console.log("Number of links: " + total_links); console.log('Flag1'); browser .waitForElementVisible('.bottom .socal>span

How to write a nightwatch custom command using jquery

醉酒当歌 提交于 2019-12-01 10:44:00
I have the following custom command written in javascript for nightwatch.js. How can I translate this to using jquery? exports.command = function (classId, indexIfNotZero) { this.browser.execute(function (classId, indexIfNotZero) { if (classId.charAt(0) == '.') { classId = classId.substring(1); } var items = document.getElementsByClassName(classId); if (items.length) { var item = indexIfNotZero ? items[indexIfNotZero] : items[0]; if (item) { item.click(); return true; } } return false; //alert(rxp); }, [classId, indexIfNotZero], function (result) { console.info(result); }); }; There are a few

How to write a nightwatch custom command using jquery

纵饮孤独 提交于 2019-12-01 08:07:31
问题 I have the following custom command written in javascript for nightwatch.js. How can I translate this to using jquery? exports.command = function (classId, indexIfNotZero) { this.browser.execute(function (classId, indexIfNotZero) { if (classId.charAt(0) == '.') { classId = classId.substring(1); } var items = document.getElementsByClassName(classId); if (items.length) { var item = indexIfNotZero ? items[indexIfNotZero] : items[0]; if (item) { item.click(); return true; } } return false; /

Nightwatch Cannot Find/Click on Dropdown Option

不打扰是莪最后的温柔 提交于 2019-12-01 03:43:36
I'm a backpacker and a programmer, trying to use the second skill to find openings in a full campsite. Rather than crawling fro scratch, I'm using the end-to-end testing framework nightwatch.js to navigate for me. I've hit a roadblock, because nightwatch is having difficulty finding a specific element using css selectors. Here are the elements and page: Here is my test code: Previous Attempts My test code will click on the selection box with #permitTypeId . It will see that #permitTypeId option is visible. It will not see or click on any of the options when more specific values are specified.

Hovering over a link in nightwatchjs

旧时模样 提交于 2019-12-01 03:12:11
I have been using nightwatch.js and always clicked around elements. Is there a way we can hover over a link or button? Abhishek Try the browser.moveToElement command. You can also fire a callback after moveToElement completes: browser.waitForElementVisible('.recommendation', 1000, function () { // moveToElement can also accept offsets browser.moveToElement('.recommendation', 100, 100, function() { browser.waitForElementVisible('.share', 500, function () { browser.click('.share'); }, "Click share icon. "); }); }, "Find a recommendation "); The code above moves to an element. After the moveTo

Nightwatchjs: how to check if element exists without creating an error/failure/exception

本小妞迷上赌 提交于 2019-11-30 11:07:25
In the page I'm testing, two buttons may be displayed: BASIC or ADVANCED. I want to be able to tell if the ADVANCED button is showing -- and if so, click it. If the BASIC button is showing, I want to do nothing and continue with my test. All of the Nightwatchjs options I've experimented with generate a failure message. For example if I "waitforpresent" or "waitforvisible" and the button is not there, it generates an error/failure. I just want to know which button is present so I can make a decision in my code. Here is what I have tried: try { browser.isVisible('#advanced-search', function

Assert text value of list of webelements using nightwatch.js

微笑、不失礼 提交于 2019-11-30 03:21:25
问题 I am new to using nightwatch.js. I want to get a list of elements and verify text value of each and every element with a given string. I have tried : function iter(elems) { elems.value.forEach(function(element) { client.elementIdValue(element.ELEMENT) }) }; client.elements('css selector', 'button.my-button.to-iterate', iter); For another stackoverflow question But what I am using right now is waitForElementPresent('elementcss', 5000).assert.containsText('elementcss','Hello') and it is

check http status code using nightwatch

末鹿安然 提交于 2019-11-30 02:51:01
问题 how do I check the HTTP status code using nightwatch.js? I tried browser.url(function (response) { browser.assert.equal(response.statusCode, 200); }); but of course that does not work. 回答1: Actually there is no way yet to get the response status of the page using Selenium (https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/141) But what you can easily do is require "request" library, make your request to the webpage you want to open in your Selenium tests and validate

Reuse the browser session for Selenium WebDriver for Nightwatch.js tests

本小妞迷上赌 提交于 2019-11-29 14:13:58
I need to write multiple tests (e.g. login test, use application once logged in tests, logout test, etc.) and need them all to be in separate files. The issue I run into is after each test, at the beginning of the next test being run, a new browser session start and it is no longer logged in due to the new session, so all my tests will fail except the login test. So, is there a way to use the same browser session to run all of my tests sequentially without having to duplicate my login code? Sorry if this is a repost but I have searched and researched and not found any answers. OR, is there a

Uploading an image file with Nightwatch.js

雨燕双飞 提交于 2019-11-29 13:20:45
I'm running front-end tests using nightwatch.js using the Chrome Driver. I need to test that image uploading works properly, presumably through the provided file input since there are callbacks that run on a successful post. I'm aware that this can be done using sendKeys method of the Selenium Web Driver. How can you accomplish this using javascript and nightwatch.js? Can you access the Selenium webdriver or an interface with it? Use this for uploading image from local desktop .setValue('input[type="file"]', require('path').resolve('/home/My-PC/Desktop/img.png')) As someone above has mentioned