码迷,mamicode.com
首页 > 其他好文 > 详细

Selenium firefox 路径设置问题

时间:2015-12-03 11:36:02      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:

方法一:重新安装Firefox在默认路径下。


 

方法二:直接用System.setProperty方法设置webdriver.firefox.bin的值 


 


import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class FirefoxDirectory {
WebDriver driver=null;


@Before
public void setUp() throws Exception {
System.setProperty("webdriver.firefox.bin", "D:\\firefox\\firefox.exe");
driver=new FirefoxDriver();
driver.get("http://www.baidu.com");
driver.manage().window().maximize();
}


@After
public void tearDown() throws Exception {
driver.quit();
}


@Test
public void test() throws InterruptedException {
//test content
}
}

 方法三:利用setCapability进行设置 


 

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class FirefoxDirectory {
    WebDriver driver=null;

    @Before
    public void setUp() throws Exception {
        DesiredCapabilities ffcapability = DesiredCapabilities.firefox();
        ffcapability.setCapability("firefox_binary", "D:\\firefox\\firefox.exe");
        driver=new FirefoxDriver(ffcapability);
        driver.get("http://www.baidu.com");
        driver.manage().window().maximize();
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
    }

    @Test
    public void test() throws InterruptedException {
        //test content
    }
}

 方法四:利用FirefoxBinary进行设置 


 

import java.io.File;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FirefoxDirectory {
    WebDriver driver=null;

    @Before
    public void setUp() throws Exception {
        File file = new File("D:\\firefox\\firefox.exe");
        FirefoxBinary firefoxbin = new FirefoxBinary(file);
        driver=new FirefoxDriver(firefoxbin,null);
        driver.get("http://www.baidu.com");
        driver.manage().window().maximize();
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
    }

    @Test
    public void test() throws InterruptedException {
        //test content
    }
}

 

Selenium firefox 路径设置问题

标签:

原文地址:http://www.cnblogs.com/miniren/p/5015397.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!