Giter VIP home page Giter VIP logo

nightwatch-commands's Introduction

Keywords

elementCount

Purpose

Read the number of elements that match a certain criteria

Parameters

  • The elementCount(locateStrategy, selector, count) keyword has three required parameters:
    • locateStrategy - can be something like css selector or xpath and is based on the selector
    • selector - is way in which we identify the element
    • count - is the number of items that we are expecting there to be

How it works

It checks the number of elements which match the selector and if it does not match the count given then it will fail the assertion.

Example

browser.page.<page>.assert.elementCount('css selector', 'ol li', 7);

getVersionNumbers

Purpose

This extracts the version number of a product from the HTML source

Parameters

The getVersionNumber(['name']) keyword accepts an array of names.

How it works

It reads in the HTML source of a page and then parses it to look for the name which is of the format name/xx.yy.zz. Where xx.yy.zz are the version numbers.

Example

browser.page.<page>.getVersionNumbers(['name']);

hideElement

Purpose

This can hide an element from the page and is useful for when performing screen comparisons and ignoring certain sections of the page

Parameters

The hideElement(elementId) keyword accepts an element ID.

How it works

It edits the styling of the HTML in question to turn the opacity to full, so it is transparent.

Example

browser.page.<page>.hideElement(elementId);

screenSize

Purpose

This provides a way of us getting the width of the browser window so we can vary the assertions in a test accordingly. For example the layout of modules is different at different screen widths.

The nightwatch supported way for getting the screen width does not work on Firefox, or the iPhone. This function provides an alternate way of doing this.

How it works

It runs some javascript in the browser which returns the width of the browser window, and returns it in the callback.

Example

browser.screenSize(function (screenSize) {
  if (screenSize >= 600) {
    // verify something on a large screen 
  } else {
    // verify something on a small screen 
  }
});

setCheckbox

Purpose

This provides a way of setting a checkbox to either true/false regardless of it's current state

Parameters

  • The setCheckbox(locateStrategy, selector, value) keyword has three required parameters:
    • locateStrategy - can be something like css selector or xpath and is based on the selector
    • selector - is way in which we identify the element
    • value - this can either be true or false depending on whether we want it checked or not

How it works

It checks the current value of the checkbox and if it does not match the value given then it will change it to be the correct value, however if it is the correct value then it will carry on without changing anything.

Example

browser.page.object.setCheckbox('css selector', '<checkbox selector>', true)

setDropdown

Purpose

This provides a way of setting a select dropdown option

Parameters

  • The setDropdown(selector, value) keyword has two required parameters:
    • selector - is way in which we identify the element
    • value - is the value which is provided inside the <option value="XXX">

How it works

It clicks the dropdown menu to show the options and then selects the appropriate value

Example

browser.page.object.setDropdown('bodyColor', '#77BC30')

nightwatch-commands's People

Contributors

gregoryduckworth avatar

Stargazers

Sibelius Seraphini avatar Cat  avatar

Watchers

Mohamed avatar James Cloos avatar  avatar Ross McFadyen avatar Dan Jones avatar Craig Phillips avatar Ross Fenning avatar Natalia Miller avatar Carwyn Nelson avatar Marty Sainty avatar Jon Ashdown avatar  avatar Lalkhum Sanga avatar Emma Young avatar Andy Webb avatar Jen Cockerill avatar  avatar Christopher Owen avatar Will White avatar  avatar Daniele Bicelli avatar James Craig avatar  avatar Andy Jones avatar

Forkers

cmorten

nightwatch-commands's Issues

Page status code

We might want to add the functionality in future where we get the response code from a webpage, this could be done by:

var request = require('request');

request('https://www.bbc.co.uk', function (error, response, body) {
    browser.assert.equal(response.statusCode, 200);
});

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.