selenium 学习2

来源:互联网 发布:win10优化工具 推荐 编辑:程序博客网 时间:2024/06/05 08:13

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

 

 2、客户端进行编写

Java代码  收藏代码
  1. public class TestPage  
  2. {  
  3.     private Selenium selenium;  
  4.     @Before  
  5.     public void setUp()  
  6.     {  
  7.         String url = "http://www.baidu.com";  
  8.         //selenium = new DefaultSelenium("localhost",SeleniumServer.getDefaultPort(),"*iexplore",url);  
  9.         <strong>selenium = new DefaultSelenium("localhost",SeleniumServer.getDefaultPort(),"*iexploreproxy",url);</strong>  
  10.         selenium.start();  
  11.     }  
  12.       
  13.     @After  
  14.     public void tearDown()  
  15.     {  
  16.         try  
  17.         {  
  18.             selenium.stop();  
  19.         } catch (RuntimeException e)  
  20.         {  
  21.             System.out.println(e.getMessage());  
  22.         }  
  23.     }  
  24.     //测试标题,文本框输入,及按钮点击  
  25.    
  26.      @Test  
  27.     public void testWeb()  
  28.     {  
  29.         System.out.println("============== test baidu=============");  
  30.         //我这里是tomcat的地址,我的tomcat端口是8888,selenium是当前工程,我让它打开首页  
  31.         selenium.open("/");  
  32.         String title = selenium.getTitle();  
  33.         //原来网页的标题  
  34.         System.out.println(title);  
  35.         selenium.type("xpath=//input[@name='wd']""helloworld");  
  36.         //得到输入的文本框的值  
  37.         System.out.println("textvalue:" + selenium.getValue("xpath=//input[@name='wd']"));  
  38.         selenium.click("xpath=//input[@id='su']");  
  39.         // selenium.waitForPageToLoad("40");  
  40.         assertEquals(title, "百度一下,你就知道");  
  41.         //输出新页的标题  
  42.          System.out.println(selenium.getTitle());  
  43.     }  
  44.           


原创粉丝点击