1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > selenium web的自动化测试工具

selenium web的自动化测试工具

时间:2024-07-03 22:56:00

相关推荐

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 = ".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(".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='/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);

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。