zoukankan      html  css  js  c++  java
  • Eclipse+JUnit+Selenium配置

    运行环境:Windows XP、Firefox。
    Firefox需要安装在标准路径下"C:Program FilesMozilla Firefoxfirefox.exe",否则需要将路径加到PATH环境变量中。

    1. 在http://seleniumhq.org/下载Selenium RC,在http://www.junit.org/下载JUint。

    2. 将下载的selenium-remote-control-1.0.3.zip解压。

    3. 用命令行进入解压的文件夹下:selenium-remote-control-1.0.3selenium-server-1.0.3。

    4. 运行java -jar selenium-server.jar 启动selenium server。

    5. 打开Eclipse,新建一个Java项目,在Propertises->Java Build Path->Libraries->Add External JARs,加入selenium-java-client-driver.jar和junit-4.8.2.jar。

    6. 在项目下新建JUnit Test Case "GoogleTest.java",粘贴下面的测试代码,Run As->JUnit Test。
    import com.thoughtworks.selenium.DefaultSelenium;
    import com.thoughtworks.selenium.Selenium;
    import junit.framework.TestCase;

    public class GoogleTest extends TestCase {
        private Selenium selenium;

        public void setUp() throws Exception {
            String url = "http://www.google.com";
            selenium = new DefaultSelenium("localhost", 4444, "*firefox", url);    //ie浏览器使用参数 "*iehta"
            selenium.start();    
        }

        protected void tearDown() throws Exception {
            selenium.stop();
        }

        public void testGoogle() throws Throwable {
            selenium.open("http://www.google.com/");
            assertEquals("Google", selenium.getTitle());
            selenium.type("q", "Selenium OpenQA");
            assertEquals("Selenium OpenQA", selenium.getValue("q"));
            selenium.click("btnG");
            selenium.waitForPageToLoad("5000");
            assertEquals("Selenium OpenQA - Google Search", selenium.getTitle());
        }
    }

  • 相关阅读:
    linux设备驱动学习笔记(1)
    linux 设备驱动程序中的一些关联性思考
    linux——(2)文件权限与目录配置
    linux——(1)初识linux
    设计模式-状态模式(State Pattern)
    设计模式-组合模式(Composite Pattern)
    设计模式-迭代器模式(Iterator Pattern)
    设计模式-模板方法模式(the Template Method Pattern)
    设计模式-外观模式(Facade Pattern)
    设计模式-适配器模式(Adapter Pattern)
  • 原文地址:https://www.cnblogs.com/pasco/p/3730224.html
Copyright © 2011-2022 走看看