Nightwatch API Learning Expect,assert

Source: Internet
Author: User

Expect

Nightwatch a new Bdd-style interface to execute assertions, called expect, in version 0.7. It is based on the Chai expect assertion library and is more flexible and efficient than the traditional asset interface.

Language Chains

The following commands are only auxiliary to improve the readability of assertions. Does not have the ability to test itself

    • To
    • Be
    • been
    • Is
    • That
    • which
    • and
    • Has
    • Have
    • With
    • At
    • Does
    • Of
. equal (value)/.contain (value)/.match (regex)

Determine if the component

    • Value is equal to the specified value
      Browser.expect.element (' #main '). Text.to.equal (' The Night Watch ');
    • Whether the value contains the specified value
      Browser.expect.element (' #main '). Text.to.contain (' The Night Watch ');
    • Whether there is a specified style
      Browser.expect.element (' #main '). To.have.css (' Display '). Which.equals (' block ');
. not

Take back write in front of Equal,contain,match text.to.not.equal ()

. Before (ms)/.after (MS)

Assert an assertion again at a specified time, which can be used in conjunction with any assertion so that it can be executed again

    • Browser.expect.element (' #main '). Text.to.contain (' The Night Watch '). before (1000);

    • Browser.expect.element (' #main '). Text.to.not.contain (' The Night Watch '). After (500);

. A (type)/an

Checks whether the type of the specified component matches the expected. Parameters with: type,message (optional)

    • Browser.expect.element (' #q '). to.be.an (' input ');
    • Browser.expect.element (' #q '). to.be.an (' input ', ' testing if #q is an input ');
    • Browser.expect.element (' #w '). TO.BE.A (' span ');
. Attribute (name)

Checks if an attribute exists for an element and has the expected value (optional)

    • Browser.expect.element (' body '). To.have.attribute (' data-attr ');
. css

With attribute

    • Browser.expect.element (' #main '). To.have.css (' Display '). Which.matches (/some\ value/);
. Enabled

Checks if an element is now available

    • Browser.expect.element (' #weblogin '). to.be.enabled;
    • Browser.expect.element (' #main '). to.not.be.enabled;
. Present

Detects if an element appears in the DOM

    • Browser.expect.element (' #main '). to.be.present;
. Select

Detect drop-down box, radio box, check box is currently selected

. text

Detects if the component has a specified text/expression that can be used with contains,equals,matches

    • . Text.to.match (/the\ night\ watch/)
. value

Same text

    • . to.have.value.which.contains/.not.equals/.that.equals
. Visible

is visible

Assert

The classic Assert&verify assertion library is still available in Nightwatch. They work the same, except that the assert skips the assertion after the current assertion fails, ends the test (equivalent to break), and verify skips the current assertion, outputs an error report, Continue to perform other assertions (equivalent to continue).

. Attributecontains ()

Checks whether an element is given a property that has the expected value
Parameters:

    1. Selector, used to locate elements
    2. Attribute, property name
    3. Expected, expected to contain the value
    4. Message (optional), description of information in test results

eg. Browser.assert.attributeContains (' #someElement ', ' href ', ' google.com ');

. Attributeequals ()

Ibid. (attributecontains)

. ContainsText ()

Parameters:

    1. Cssselector
    2. Expectedtext
    3. MSG (Optional)

eg. Browser.assert.containsText ("#main", "The Night Watch");

. Cssclasspresent ()

Checks whether the element has the specified CSS class name
Parameters:

    1. Cssselector, used to locate elements
    2. ClassName, expecting some class names
    3. Message (optional), description of information in test results

eg. Browser.assert.cssClassPresent ("#main", "container");

. Cssclassnotpresent ()

Upstairs (. cssclasspresent) Take counter

. Cssproperty ()

Checks whether the specified property of an element is the desired state
Parameters:

    1. Cssselector, used to locate elements
    2. Cssproperty, properties
    3. Expected,
    4. Message (optional), description of information in test results

eg. Browser.assert.cssProperty ("#main", "Display", "block");

. Elementpresent ()

Whether the DOM contains the specified element

    • Browser.assert.elementPresent ("#main");
. Elementnotpresent ()

Upstairs take the counter

. Hidden ()

Checks whether the specified element is not visible on the page

    • Browser.assert.hidden (". should_not_be_visible");
. Title ()

Checks whether the page title is a specified title

    • Browser.assert.title ("Nightwatch.js");
. Urlcontains ()

Checks whether the current URL contains a specified value

    • Browser.assert.urlContains (' Google ');
. Urlequals ()
    • Browser.assert.urlEquals (' http://www.google.com ');
. Value ()

Checks whether the value of the specified form element is equal to the specified value

    • Browser.assert.value ("Form.login input[type=text]", "username");
. Valuecontains ()
    • Browser.assert.valueContains ("Form.login input[type=text]", "username");
. Visible ()
    • Browser.assert.visible (". should_be_visible");
Commands

Commands can perform different actions on a page, typically containing two or more page-driven protocol behaviors.

callback function

The following methods support callback functions. The callback function executes after the command is completed

. ClearValue ()

Can clean up text field or text input box contents

    • Client.clearvalue (' input[type=text] ');
. Click ()

Simulate Click events

    • Client.click ("#main ul Li A.first");

Feel more suitable for use with callback functions
Browser.click ("#main ul li A.first", function (response) {
This.assert.ok (Browser = = = This, "Check if the context was right.");
This.assert.ok (typeof response = = "Object", "We got a Response object.");
});

. CloseWindow ()

Close the current window when you use multiple windows

. Deletecookie ()

Delete Cookies

Nightwatch API Learning Expect,assert

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.