本文主要是介绍java+junit+selenium+Eclipse,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原文转自 https://blog.csdn.net/zm_21/article/details/28235177
1. Create a java project
2. Right click project name -> "Build Path"->"Add Library"->"JUnit"->"JUnit4"
3. New a java class file
4. Add the below,
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.Assert;
import com.thoughtworks.selenium.SeleneseTestBase;
import com.thoughtworks.selenium.DefaultSelenium;
public class TestWeb extends SeleneseTestBase{
DefaultSelenium selenium = null;
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost",4444,"*firefox3 D:\\Program Files\\Mozilla Firefox\\firefox.exe",
"http://www.baidu.com");
selenium.start();
}
@Test
public void testBaiduSearch() throws Exception {
selenium.open("http://www.baidu.com");
Thread.sleep(5000);
selenium.type("id=kw1", "selenium");
selenium.click("id=su1");
Thread.sleep(5000);
Assert.assertEquals("selenium_百度搜索", selenium.getTitle());
Thread.sleep(5000);
}
@After
public void tearDown()throws Exception {
selenium.stop();
}
}
Notice:
//selenium.waitForPageToLoad("50000"); is no use, so use Thread.sleep
5. Right click project name-> Run as->Junit test
这篇关于java+junit+selenium+Eclipse的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!