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 example
type
Command, 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:
- Go to testselenium2.html to open the address change page.
- In
q
In the text boxBetelgeuse state prison
.
- Click the input area named 'btnzzk. Note: UseXpathFindSubmitButton, which causes the form data to be sent to the server.
- Verify that the page contains text
Address 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.