Giter Club home page Giter Club logo

nightwatch-custom-commands-assertions's Introduction

Nightwatch custom commands and assertions

Build Status npm version

These are some commands and assertion I use when I'm testing with nightwatch.js and selenium.

How to use these things?

You can install it using npm:

npm install nightwatch-custom-commands-assertions --save-dev

Then, open the nightwatch.json file in your editor (or create it if it doesn't exist) and edit the custom_commands_path and custom_assertions_path keys so they look like this:

{
	... //your config
	
	"custom_commands_path" : "node_modules/nightwatch-custom-commands-assertions/js/commands",
	"custom_assertions_path" : "node_modules/nightwatch-custom-commands-assertions/js/assertions",
	
	... //your config again
}

Now you should be able to use these commands/assertions when you call nightwatch --test.

Alternative ways of installing

  • Go into your tests folder (or where your nightwatch.json is) and do:

    git clone https://github.com/maxgalbu/nightwatch-custom-commands-assertions.git
    
  • Download the zipped repository here and extract it wherever you want

You then need to open your nightwatch.json and edit custom_commands_path and custom_assertions_path according to where you cloned or extracted the repository.

Contributing

See Contributing.md.

List of commands

See the docs folder

nightwatch-custom-commands-assertions's People

Contributors

dependabot[bot] avatar jehon avatar maxgalbu avatar rober710 avatar rukeba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nightwatch-custom-commands-assertions's Issues

Issues with assertions and pageObjects.

Hello, today I've wanted to use pageObjects with .assert.elHasChildren command. It works without pageobjects, but when I try to combine it with pageObjects (I do this good way), I'm getting this error in console:

Running:  Solutions page tests should check that articles list contains childs (articles)
Error while running execute command: Converting circular structure to JSON
    at command (/x/assertions/elHasChildren.js:73:21)
    at module.exports.BaseAssertion._scheduleAssertion (/usr/local/lib/node_modules/nightwatch/lib/core/assertion.js:86:17)
    at module.exports.BaseAssertion._executeCommand (/usr/local/lib/node_modules/nightwatch/lib/core/assertion.js:81:17)
    at AssertionInstance.commandFn [as _commandFn] (/usr/local/lib/node_modules/nightwatch/lib/core/assertion.js:163:21)
    at AsyncTree.runCommand (/usr/local/lib/node_modules/nightwatch/lib/core/queue.js:157:30)
    at AsyncTree.runChildNode (/usr/local/lib/node_modules/nightwatch/lib/core/queue.js:117:8)
    at AsyncTree.walkDown (/usr/local/lib/node_modules/nightwatch/lib/core/queue.js:83:10)
    at AsyncTree.walkUp (/usr/local/lib/node_modules/nightwatch/lib/core/queue.js:100:8)
    at AsyncTree.walkDown (/usr/local/lib/node_modules/nightwatch/lib/core/queue.js:93:12)
    at AsyncTree.traverse (/usr/local/lib/node_modules/nightwatch/lib/core/queue.js:71:10)

Any ideas? Would love to hear!

Question: elementHasChildrenCount

Hi,

I've been trying to implement a solution which counts the number of elements on a page and then passes the test if there <=26 of the required elements.

Is this possible using this assertion?

Many thanks!

Unexpected Present

Hi,

I was using jqueryElementPresent and discovered that if the selector has a syntax error, then the method will still conclude that the element is present.

For example, I was using the following
.assert.jqueryElementPresent('tr.visitorRow:has(> td.visitorName:contains('+visitor["name"]+')))')

Even though the selector has an extra ), the statement would evaluate that the element is present even though it isn't. I'm not sure if this is expected behavior or something that you may want to create an exception for.

Thanks!

FEATURE REQUEST: Allow Sharing of Page Sections

Hi there,

Using the example provided in the docs I am trying to share a nested "section" inside of some other sections, which seems to work for elements but not for sections which contain elements.

I suppose this is more of a feature request, since it isn't explicitly explained in the docs but I was hoping I could share sections the same way one shares elements.

Example:

//myPageObject.js
const sharedSections = {
  details: {
    selector: '.text-info',
    elements: {
      title: 'h2',
      ourCars: '.car-examples',
      capacity: '.capacity'
    }
  },
  priceBox: {
    selector: '.price-box',
    elements: {
      total: '.price',
      price: '.base_price',
      meetAndGreet: '.airport_fee',
      select: '.btn-continue'
    }
  }
}

const sharedElements = {
  image: '.car-image img'
}

module.exports = {
  sections: {
    carClass: {
      commands: [sharedCommands],
      selector: '[ng-controller="VehicleSelectController"]',
      sections: {
        business: {
          selector: '#vehicle-class-business',
          elements: [sharedElements],
          sections: [sharedSections]
        },
        businessVan: {
          selector: '#vehicle-class-van',
          elements: [sharedElements],
          sections: [sharedSections]
        },
        firstClass: {
          selector: '#vehicle-class-first',
          elements: [sharedElements],
          sections: [sharedSections]
        }
      }
    }
  }
}

feature request: waitForJqueryElementVisible

I'd love to see an implementation of waitForElementVisible refactored to work with jqueryElementPresent

perhaps: browser.waitForJqueryElementVisible(selector, time, abortOnFail, callback, msg)

I tried my hand on implementing, but was not able to get it working...

ref:

jqueryElementNotPresent wokr wrong

Hello

assertion jqueryElementNotPresent works incorrectly - it's not fail when selector exists on the page.

Problem in js/assertions/jqueryElementNotPresent.js value method.Result never contains field "value" instead it contains ELEMENT field. If change then method began work correctly.

Problems with jQueryElement

Here is my code:

 .jqueryElement("body", function(element) {
                console.log("EL", element)
            })

After launch It breaks my test, and giving an error :

{ additionalInformation: '\nDriver info: driver.version: unknown',
  localizedMessage: '$ is not defined\nBuild info: version: \'2.47.1\', revision: \'411b314\', time: \'2015-07-30 03:03:16\'\nSystem info: host: \'N/A\', ip: \'N/A\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'3.19.0-15-generic\', java.version: \'1.8.0_45\'\nDriver info: driver.version: unknown',
  supportUrl: null,
  systemInformation: 'System info: host: \'N/A\', ip: \'N/A\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'3.19.0-15-generic\', java.version: \'1.8.0_45\'',
  cause: null,
  suppressed: [],
  message: '$ is not defined\nBuild info: version: \'2.47.1\', revision: \'411b314\', time: \'2015-07-30 03:03:16\'\nSystem info: host: \'N/A\', ip: \'N/A\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'3.19.0-15-generic\', java.version: \'1.8.0_45\'\nDriver info: driver.version: unknown',
  hCode: 86066378,
  class: 'org.openqa.selenium.WebDriverException',
  buildInformation: 
   { buildRevision: '411b314',
     buildTime: '2015-07-30 03:03:16',
     releaseLabel: '2.47.1',
     hCode: 368747769,
     class: 'org.openqa.selenium.internal.BuildInfo' } }

Obviously, jQuery wasn't found. How can I require jQuery? Or maybe I something missing?

Doesn't work with PageObjects in Nightwatch.js

Just a simple question - does this custom assertions support Nightwatch.js page objects? I’m not able to get it working, so I think they doesn’t or I’m doing something wrong.

When I use:
browser.page.homePage().section.mainSearch.jqueryClick("@searchResults:contains('Barack Obama')”)

It doesn’t work (provided log in gist).

When I’m not using page objects - it works.
browser.jqueryClick(".search-result-name:contains('Barack Obama')”)

When I’m using normal .click command from nightwatch.js, it works with same pageObjects but as you probably know it only selects first element it finds.

Can you please clarify? Thanks!

https://gist.github.com/drptbl/a3cbfcee551fb4923e77

setSelect2Data trigger problem

Any code that pulls 'val' from the select2 change event object will not run with the setSelect2Data command. To fix, and kill a line of code, you can do:

$(selector).select2("data", data, true);
//$(selector).trigger("change"); // not needed when true is set above.

Thanks

waitForText default time

is there a defautl time set in waitForText() function?

if i dont set a max time i get this error
Expression wasn't true in 10000 ms. - expected "expression true" but got: expression false

if i set a max time to 10000
the element was found after 49ms

Add waitForValue

Hi, first of all, thanks for your commands.
In fact, this comment is not a found bug else a suggestion.

Could you add the command waitForValue, that has the same functionality that waitForText, the change is just change getText by getValue.

I had an scenario where a form is populated and one input text shows the value after a service responds.

I think if you add that new command would be great, what I did so far was create the command locally but I think if you add the waitForValue command many people could benefit.

Thanks

Request: mysql assertion

After doing an action, I would like to verify that in mysql it set that field to the appropriate value. In this case a simple 0 or a 1

does waitforAttribute work with Page Objects?

I'm trying https://github.com/maxgalbu/nightwatch-custom-commands-assertions/blob/master/docs/waitForAttribute.md

I'm trying to use it to wait for a button do be enabled


    .waitForAttribute("@continueButton", "disabled", function(disabled) {
      return !disabled;
    });

but getting Error while running getAttribute command: Converting circular structure to JSON

when i use the regular css selector, as in :


    .waitForAttribute(".cart .continueButton", "disabled", function(disabled) {
      return !disabled;
    });

It works as expected.

But i'd prefer to use the page object syntax, as described in http://nightwatchjs.org/guide#page-objects

Is there a plan to add support for page objects?

WaitForJqueryAjaxRequest incorrect Example

image

for WebStorm, "WaitForJqueryAjaxRequest" is a function and "waitForJqueryAjaxRequest" is not defined. When i run nightwatch, "WaitForJqueryAjaxRequest" is not a function but "waitForJqueryAjaxRequest" is working.

image

in jsDoc, example is wrong.

Note: Excuse My English :)

waitForDocumentLoaded() throws an error

I was really interested in using this custom command waitForDocumentLoaded() to speed up my tests.
However, it throws an error:

Error while running "execute" command: _this2.client.assertion is not a function
       TypeError: Error while running "execute" command: _this2.client.assertion is not a function
 at /project_path/node_modules/nightwatch-custom-commands-assertions/js/commands/waitForDocumentLoaded.js:76:31
           at NightwatchAPI.<anonymous> (/project_path/node_modules/nightwatch-custom-commands-assertions/js/commands/waitForDocumentLoaded.js:90:28)
           at Function.makePromise (/project_path/node_modules/nightwatch/lib/utils/index.js:128:28)
           at method.then (/project_path/node_modules/nightwatch/lib/index.js:130:62)
           at process._tickCallback (internal/process/next_tick.js:68:7)

If I just the waitForDocumentLoaded test from your module (nom run test), I also get the same error.

Install gulp and coffeelint globally

The npm package try to install gulp and coffelint globally, which fail in my setup.

Is it really necessary?

I would expect the package to work without global installation.

Thanks in advance

Command used:
$ npm install --save-dev nightwatch-custom-commands-assertions

Here is the complete log:

[email protected] preinstall /var/www/cryptomedic/node_modules/nightwatch-custom-commands-assertions
npm install -g gulp coffeelint nightwatch
npm ERR! tar.unpack untar error /home/jehon/.npm/nightwatch/0.6.13/package.tgz
npm ERR! tar.unpack untar error /home/jehon/.npm/coffeelint/1.10.0/package.tgz
npm ERR! Linux 3.16.0-38-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "gulp" "coffeelint" "nightwatch"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! path /usr/lib/node_modules/nightwatch
npm ERR! code EACCES
npm ERR! errno -13

npm ERR! Error: EACCES, mkdir '/usr/lib/node_modules/nightwatch'
npm ERR! at Error (native)
npm ERR! { [Error: EACCES, mkdir '/usr/lib/node_modules/nightwatch']
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/lib/node_modules/nightwatch',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/lib/node_modules/nightwatch',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:35:25',
npm ERR! '/usr/lib/node_modules/npm/node_modules/mkdirp/index.js:47:53',
npm ERR! 'FSReqWrap.oncomplete (fs.js:95:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! error rolling back Error: EACCES, unlink '/usr/bin/gulp'
npm ERR! error rolling back at Error (native)
npm ERR! error rolling back { [Error: EACCES, unlink '/usr/bin/gulp'] errno: -13, code: 'EACCES', path: '/usr/bin/gulp' }

npm ERR! Please include the following file with any support request:
npm ERR! /var/www/cryptomedic/node_modules/nightwatch-custom-commands-assertions/npm-debug.log
npm ERR! Linux 3.16.0-38-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "--save-dev" "nightwatch-custom-commands-assertions"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! code ELIFECYCLE

npm ERR! [email protected] preinstall: npm install -g gulp coffeelint nightwatch
npm ERR! Exit status 243
npm ERR!
npm ERR! Failed at the [email protected] preinstall script 'npm install -g gulp coffeelint nightwatch'.
npm ERR! This is most likely a problem with the nightwatch-custom-commands-assertions package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm install -g gulp coffeelint nightwatch
npm ERR! You can get their info via:
npm ERR! npm owner ls nightwatch-custom-commands-assertions
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /var/www/cryptomedic/npm-debug.log

SaveElementScreenshot not working correctly

Using the completely unedited version of the custom command, it's not working for specified elements on my site, google.com, bing.com. The size is correct, but the location is not.

There's several issues in EasyImage about crop and gravity not working. I went into the Easy Image code and removed all the passing of gravity options, but my images still don't crop to the correct place.

If this isn't some weird local issue for me and a bunch of other people, I would assume this is a recent issue in Easy Image, maybe caused by this commit - hacksparrow/node-easyimage@3ca8c42 where they modified the arguments heavily.

I don't need this feature from Nightwatch or have time to look into it specifically, but there ya go.

problems with jqueryclick using headless (Jenkins)

hi,
I have installed your custom commands, so that we could run our tests in Jenkins
https://github.com/maxgalbu/nightwatch-custom-commands-assertions

I am having some issues when running via headless or non-headless (i.e. browser=chrome)

"Send a Private message":function (browser) {
browser
.assert.jqueryElementPresent("h3('Private messages')")
.pause(4000)
.waitForJqueryElement("xxxx > li:last-child:visibile", 10000)
.jqueryClick("xxxxt > li:first-child")
.pause(4000)
.assert.jqueryElementPresent("h3('Conversation')")
.jqueryElement("xxxx123") //same element
.jqueryClick("xxxx123") //same element
.pause(6000)
.setValueAndTrigger("xxxx123", "Automation Rules 123$%^&* ;-)")
.keys(['\uE006'])
.jqueryElement("xxx1234")
.jqueryClick("xxx1234")

when i run NOT headless (browser=chrome), it works perfectly
but in HEADLESS via Jenkins, it is always failing

without headless OK
✔ Testing if element <h3('Private messages')> is present.
✔ Testing if element <h3('Conversation')> is present.
✔ Testing if element div:xxx123 is present.
✔ Testing if element <xxx1234('Send')> is present.
✔ Testing if element is present.

Headless NOK
✔ Testing if element <h3('Private messages')> is present.
✔ Testing if element <h3('Conversation')> is present.
✖ Testing if element div:xxx123 is present. - expected "present" but got: null

FAILED: 1 assertions failed, 2 passed and 10 skipped (9.598s)

what am i doing wrong?

Suppress error messages while waiting for element

I'm using .waitForText and it works correctly except that it displays error messages while waiting for the element to load.

Running:  Job adding
ERROR: Unable to locate element: "#foobar" using: css selector
ERROR: Unable to locate element: "#foobar" using: css selector
...
 ✔ waitForText: #foobar. Expression was true after 1588 ms.

My guess is that these are coming from api.getText()

Is there a way to suppress these error messages?

jqueryClick not clicking element

In my test, jqueryClick() isn't actually performing a click. It throws no errors, but it's not navigating to the page linked to by the tag that's supposed to be clicked.

In my chain of browser...() calls, I have these three calls:

    .assert.jqueryElementPresent("a:contains('Add to Cart')")
    .jqueryClick("a:contains('Add to Cart'):last")
    .waitForElementVisible('body', 1000)

The assert passes, and no errors/failures are reported by Nightwatch, but no actual "click" is taking place. I watch the browser open and perform the calls, but the link is never actually getting clicked (so, in this example, the browser stays on the last page without ever going to the page "Add to Cart" links to).

Am I doing something wrong, or is this a bug?

elementHasChildrenCount ignores child_selector

When attempting to use elementHasChildrenCount with a child selector, the value of child_selector is undefined inside the execute() function.

Steps to recreate:

The issues comes when trying to select a deep child from a parent:

<div id="parent">
    <div>
        <div class="target_child">Child 1</div>
        <div class="target_child">Child 2</div>
    </div>
</div>

Then in your test, try the following:

{
 // ...

    "Child count should be valid": browser => {
          browser.assert.elementHasChildrenCount("#parent", 2, ".target_child");
         // FAILS with count of 1
    },

// ...
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.