Selenium 学习札记2

Selenium 学习笔记2

启动完成服务器后,可以进行客户端代码的开发了:

 

 2、客户端进行编写

public class TestPage
{
	private Selenium selenium;
	@Before
	public void setUp()
	{
		String url = "http://www.baidu.com";
		//selenium = new DefaultSelenium("localhost",SeleniumServer.getDefaultPort(),"*iexplore",url);
		selenium = new DefaultSelenium("localhost",SeleniumServer.getDefaultPort(),"*iexploreproxy",url);
		selenium.start();
	}
	
	@After
	public void tearDown()
	{
		try
		{
			selenium.stop();
		} catch (RuntimeException e)
		{
			System.out.println(e.getMessage());
		}
	}
	//测试标题,文本框输入,及按钮点击
 
	 @Test
	public void testWeb()
	{
		System.out.println("============== test baidu=============");
		//我这里是tomcat的地址,我的tomcat端口是8888,selenium是当前工程,我让它打开首页
		selenium.open("/");
		String title = selenium.getTitle();
		//原来网页的标题
		System.out.println(title);
		selenium.type("xpath=//input[@name='wd']", "helloworld");
		//得到输入的文本框的值
		System.out.println("textvalue:" + selenium.getValue("xpath=//input[@name='wd']"));
		selenium.click("xpath=//input[@id='su']");
		// selenium.waitForPageToLoad("40");
		assertEquals(title, "百度一下,你就知道");
		//输出新页的标题
		 System.out.println(selenium.getTitle());
	}
 	 	
}

你可能感兴趣的:(tomcat,String,服务器,url,Class,selenium)