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中查找问题

  • 相关阅读:
    锐浪报表应用系列二
    论产品和项目
    我的处女作
    今天晚上吃什么?
    今日晚餐
    PYTHON+数据库
    周末看到小区有个阿姨溜羊驼
    AD 10使用技巧---新学习
    使用.NET进行高效率互联网敏捷开发的思考和探索【一、概述】
    【开发随感】【一】【开发基础的基础】
  • 原文地址:https://www.cnblogs.com/keeping/p/2296447.html
Copyright © 2011-2022 走看看