package com.example.tests;
import com.thoughtworks.selenium.*;
import org.junit.*;
import java.util.regex.Pattern;
import org.openqa.selenium.server.SeleniumServer;
@SuppressWarnings("deprecation")
public class TestCase extends SeleneseTestCase {
/**
* @throws java.lang.Exception
static SeleniumServer server;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.out.print("setupBeforeClass\n");
server = new SeleniumServer();
server.start();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
System.out.print("tearDownAfterClass\n");
server.stop();
}
*/
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*firefox3 D:\\Firefox\\firefox.exe",
"http://www.2345.com/");
selenium.start();
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
@Test
public void testTestCase() throws Exception {
selenium.open("/?ied");
selenium.click("id=search1");
selenium.click("css=input.sbutton");
// selenium.click("link=新 闻");
// selenium.waitForPageToLoad("30000");
// selenium.click("css=font");
// selenium.click("link=民政部:20日以来强降雨致全国95人死亡45人失踪");
}
}
import com.thoughtworks.selenium.*;
import org.junit.*;
import java.util.regex.Pattern;
import org.openqa.selenium.server.SeleniumServer;
@SuppressWarnings("deprecation")
public class TestCase extends SeleneseTestCase {
/**
* @throws java.lang.Exception
static SeleniumServer server;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.out.print("setupBeforeClass\n");
server = new SeleniumServer();
server.start();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
System.out.print("tearDownAfterClass\n");
server.stop();
}
*/
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*firefox3 D:\\Firefox\\firefox.exe",
"http://www.2345.com/");
selenium.start();
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
@Test
public void testTestCase() throws Exception {
selenium.open("/?ied");
selenium.click("id=search1");
selenium.click("css=input.sbutton");
// selenium.click("link=新 闻");
// selenium.waitForPageToLoad("30000");
// selenium.click("css=font");
// selenium.click("link=民政部:20日以来强降雨致全国95人死亡45人失踪");
}
}
本文提供了一个使用Selenium进行自动化测试的示例代码,通过Java实现了针对特定网站的基本交互操作,包括打开页面、点击搜索框等。该测试案例展示了如何初始化Selenium、执行基本的浏览器操作及清理工作。
904

被折叠的 条评论
为什么被折叠?



