Selenium-java (2)

Source: Internet
Author: User
Tags assert python script

1. Set the wait time

Thread.Sleep (2000); (1000 stands for 1s)

2. Assert Assertion:

Verify that the state of your application is consistent with what you expect.

Common assertions include verifying the contents of a page, such as whether the title is x or the current position is correct, or verifying that the check box is checked.

Assertions are used in three modes: Assert, verify, waitfor

When an Assert fails, the test terminates.

When the Verify fails, the test continues to execute and the error is recorded in the day display. This allows this single validation to pass. Make sure that the application is on the correct page.

WAITFOR is used to wait for certain conditions to become true. Tests that can be used for AJAX applications.

If the condition is true, they will execute successfully immediately. If the condition is not true, the test will fail and be paused. Until the current time-out is exceeded. Usually with settimeout time

assertions commonly used are :

Assertlocation (Judging is currently on the right page),

Asserttitle (check that the title of the current page is correct),

Assertvalue (Check the value of input, checkbox or radio, with a value of "on" inaction "off"),

assertselected (check if select is correct in the drop-down menu),

Assertselectedoptions (check if the options in the drop-down menu are correct),

Asserttext (checks the text of the specified element),

Asserttextpresent (checks if the specified text appears on the page currently displayed to the user),

Asserttextnotpresent (checks if the specified text does not appear on the page currently displayed to the user),

Assertattribute (checks the value of the property of the currently specified element),

Asserttable (check the value in a cell in the table),

Asserteditable (checks whether the specified input can be edited),

Assertnoteditable (checks whether the specified input cannot be edited),

Assertalert (check if there is an alert dialog box with the specified message),

Waitforelementpresent (waits for an element to be checked for existence.) Is true, it is executed. )

The most commonly used unittest assertions are as follows:

1. Equality Assertion: assertequal (self, first, second, msg=none) is often used for title and URL comparisons to check for consistency with expected results;

Self.assertequal (U ' users-delicate Cloud Dashboard ', driver.title, ' Switch to Admin_identity_user panel fail ')

2. Unequal assertion: assertnotequal (self, first, second, msg=none) and 1 instead, this assertion is not commonly used;

3.True Assertion: asserttrue (self, expr, msg=none) This assertion can be used to judge an expression looking for an element, such as returning true to pass, otherwise fail;

4.False Assertion: Assertfalse (self, expr, msg=none) This assertion can be used to determine an expression that looks for an element, such as a return false, or fail;

3 and 4 can be used in conjunction with the Python script generated by the Selenium IDE is_element_present and is_alert_present;

Selenium-java (2)

Related Article

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.