Understanding selenium-test runner mode and usage

Source: Internet
Author: User

Test runner Mode

Selenium test runner script, also knownTest Case), Is written in HTML language through a simple table layout, the following code:

Selenium test case structure

 table border="1">    tr>      td>First commandtd>      td>Targettd>      td>Valuetd>    tr>    tr>      td>Second commandtd>      td>Targettd>      td>Valuetd>    tr>  table>
The test runner script is usually deployed on the same server as the tested application (AUT.
This is because browser Bot uses JavaScript to simulate user operations.
These scripts are run in a restricted sandbox environment.
If you need to bypass these restrictions, you can use a proxy.

The test runner script uses the same test suite and test case concepts as the xunit framework. Test Cases and commands are executed in sequence as they appear in the test suite and test cases.

In the above Code:

  • The first column containsCommandOrAssertions.
  • The second column contains commands or assertionsTarget). You can use one of the multiple supported component locators to specify the target. The ID or name of the component is usually used,However, XPath and Dom delimiters are also supported.
  • The third column containsValue. For exampletypeCommand, this column may be the expected value of a text field.

 

Even for non-technical personnel, the test runner script is easy to read and write. When you open the example in the above Code in a browser, you will get a table like this:

First Command Target Value
Second command Target Value

 

Test Case instance

When you execute the following test script:

  1. Go to testselenium2.html to open the address change page.
  2. Inq In the text boxBetelgeuse state prison.
  3. Click the input area named 'btnzzk. Note: UseXpathFindSubmitButton, which causes the form data to be sent to the server.
  4. Verify that the page contains textAddress change successful.
table>    tr>      td>opentd>      td>TestSelenium2.htmltd>      td>td>    tr>    tr>      td>typetd>      td>//input[@id='q']td>      td>Betelgeuse state prisontd>    tr>    tr>      td>clicktd>      td>//input[@id='btnZzk']td>      td>td>    tr>    tr>      td>verifyTextPresenttd>      td>Address change successfultd>      td>td>    tr>  table>
The code here seems very similar to the code used for selenium RC testing. The difference is that RC is tested using an advanced programming language that we usually use, the test runner is represented in HTML.
The content of my testselenium2.html page is very simple:
Input type = "text" id = "Q"/> input type = "button" id = "btnzzk" onclick = "zzk () "text =" "/> Div id =" div1 "> div> SCRIPT> function zzk () {document. getelementbyid ("div1 "). innerhtml = "address change successful";} SCRIPT>
 
 

Click "Run selected test" on the right to start the test:

The running is all green, indicating that it passes.

1run, 1 passed, run the test.

The testselenium2.html page we want to test is what we expect.

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.