- Install Firefox
- Install Java JDK
- Install Selenium IDE from official download site
<html>
<head>
<link rel="selenium.base" href="http://www.google.com.au/" />
<title>1</title>
</head>
<body>
<table>
<thead><tr><td>1</td></tr></thead>
<tbody>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=gs_tti0</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=gbqfq</td>
<td>selenium ide</td>
</tr>
<tr>
<td>click</td>
<td>id=gbqfb</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Selenium IDE</td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
Export test case as Java JUnit4 Remote Control -
package com.example.tests;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.regex.Pattern;
public class 123 {
private Selenium selenium;
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.com.au/");
selenium.start();
}
@Test
public void test123() throws Exception {
selenium.open("/");
selenium.click("id=gs_tti0");
selenium.type("id=gbqfq", "selenium ide");
selenium.click("id=gbqfb");
assertTrue(selenium.isTextPresent("Selenium IDE"));
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}
Test log -
[info] Executing: |open | / | |
[info] Executing: |click | id=gs_tti0 | |
[info] Executing: |type | id=gbqfq | selenium ide |
[info] Executing: |click | id=gbqfb | |
[info] Executing: |assertTextPresent | Selenium IDE | |
Add another test case then save test suite as ts.html -
<html>
<head>
<title>Test Suite</title>
</head>
<body>
<table class="selenium"><tbody>
<tr><td><b>Test Suite</b></td></tr>
<tr><td><a href="1.html">123</a></td></tr>
<tr><td><a href="2.html">246</a></td></tr>
</tbody></table>
</body>
</html>
Export test suite as Java Junit4 Remote Control -
import junit.framework.Test;
import junit.framework.TestSuite;
public class Ts {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(123.class);
suite.addTestSuite(246.class);
return suite;
}
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
}
No comments:
Post a Comment