zoukankan      html  css  js  c++  java
  • 四.Selenium与Junit结合

    前提:必须安装了eclipse,且在eclipse中新建了project,如project名称为test

    1.对test加载selenium-server-standalone-2.15.0.jar包及Junit4包

    2.将Selenium IDE中录制的脚本转换成Junit 4(options-->format-->Junit 4(Remote control)),对转换后的脚本进行复制,拷贝至eclipse的某个新建测试类中

    3.修改代码:在setup()方法中增加Selenium RC启动方法,否则运行失败

    public class SampleTest extends SeleneseTestCase {

    SeleniumServer SELENIUM_SERVER;
     @Before
     public void setUp() throws Exception {
      RemoteControlConfiguration rcc = new RemoteControlConfiguration();
      rcc.setPort(4444); 
      SELENIUM_SERVER = new SeleniumServer(rcc);
      SELENIUM_SERVER.start();

       //若Firefox是默认安装,则不需要指定路径“*firefox”即可;最后参数为URL
      selenium = new DefaultSelenium("localhost", 4444, "*firefox D:/Program Files/Mozilla Firefox 4.0.1/firefox.exe", "http://ip:8085/xx/aa.jsf/");
      selenium.start();
     }

    @Test
     public void testUntitled() throws Exception {
      selenium.open("/xx/aa.jsf");
      assertEquals("xx系统", selenium.getTitle());//获取URL标题
      selenium.type("id=ext-comp-12", "admin");//输入用户名
      assertTrue(selenium.isElementPresent("xpath=//input[@id='ext-comp-1012']"));
      selenium.type("id=ext-comp-13", "123");//输入密码
      Thread.sleep(2000);//等待2S装载数据
      selenium.clickAt("id=ext-gen4","登录");//点击登录按钮
      selenium.waitForPageToLoad("30000");

      .....

      .....
     

     }

     @After
     public void tearDown() throws Exception {
      selenium.stop();
      SELENIUM_SERVER.stop();
     }

     注:运行Testcase时出现错误,建议在https://groups.google.com/forum/#!forum/selenium-users中查找问题

  • 相关阅读:
    java 根据对象属性排序
    无法初始化SFTP协议。主机是SFTP服务器吗
    Spring IOC 学习(三)IOC容器的依赖注入
    Spring-IOC学习-02 IOC容器初始化
    nginx简单使用
    Spring-IOC学习-01 IOC重要的几个接口定义
    Spring-IOC学习
    Http Service
    C#从入门到放弃--字符串类型转数字类型
    VS系列--快捷键的使用
  • 原文地址:https://www.cnblogs.com/keeping/p/2296447.html
Copyright © 2011-2022 走看看