selenium web的自动化测试工具

1)导入jar包:


2)父测试类:

AbstractTest:

package org.selenium.one;


import java.io.File;


import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;


public abstract class AbstractTest {
/*
* 用java程序打开selenium server的方法,不必使用cmd.并设置了selenium server和selenium的基本配置
*/
protected static Selenium selenium;
protected static SeleniumServer seleniumServer;
public static String browser = "*iexplore";//"*chrome";//
public static String url = "http://www.google.com.hk/";

@BeforeClass
public static void setUp() throws Exception {
startSeleniumServer();
selenium = new DefaultSelenium("localhost", 4444, browser, url);
selenium.start();
}

private static void startSeleniumServer() throws Exception {
String template = "C:/wordspace/selenium-templates";
RemoteControlConfiguration rcConf = new RemoteControlConfiguration();
rcConf.setPort(4444);
rcConf.setReuseBrowserSessions(true);
rcConf.setBrowserSideLogEnabled(true);
rcConf.setSingleWindow(true);
rcConf.setFirefoxProfileTemplate(new File(template));
seleniumServer = new SeleniumServer(rcConf);
seleniumServer.start();
}


@AfterClass
public static void tearDown() throws Exception {
selenium.stop();
seleniumServer.stop();
}
}


3)真正测试类:

package org.selenium.one;


import org.junit.Test;


public class RCSerchHI extends AbstractTest {
private final String DEFAULT_TIMEOUT = "100000";


// @Test
// public void searchHelloWordByGoogle() {
// selenium.open("http://www.google.com.hk/");
// selenium.waitForPageToLoad(DEFAULT_TIMEOUT);
// selenium.type("q", "hello world");// 取name值,但多个元素的同名就取不到了
// // td下面的input标签属性title等于Google Search
// // selenium.type("//td/input[@title='Google Search']", "hello world");
// selenium.click("btnK");
// selenium.waitForPageToLoad(DEFAULT_TIMEOUT);
// selenium.click("//a[@href='http://en.wikipedia.org/wiki/Hello_world_program']");
// selenium.waitForPageToLoad(DEFAULT_TIMEOUT);
// Assert.assertTrue(selenium.isTextPresent("\"Hello, World!\""));
// }

@Test
public void searchEwingByGoogle() {
selenium.open("http://10.0.0.60:8090/WebHost/index");
selenium.waitForPageToLoad(DEFAULT_TIMEOUT);
selenium.type("username", "1");// 取name值,但多个元素的同名就取不到了
selenium.type("pwd", "1");// 取name值,但多个元素的同名就取不到了
// td下面的input标签属性title等于Google Search
selenium.click("//a[@href=\"javascript:userLogin();\"]");
selenium.waitForPageToLoad(DEFAULT_TIMEOUT);

}

}

转载于:https://www.cnblogs.com/sunxiangfu/archive/2013/03/15/4261056.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值