Selenium firefox打开2火狐(附CDI)

时间:2015-03-06 19:37:14

标签: firefox selenium cdi

我正在使用含有CDI的硒来创建它,每次使用它时,selenium打开2个firefox并使用一个,而另一个打开。

我正在使用CDI创建FirefoxDriver,因此我可以在各个地方注入和使用它。 他们是我创造的方式:

@ApplicationScoped
public class FirefoxDriverProducer {

    @RequestScoped
    @Produces 
    public FirefoxDriver getDriver() {
        String caminhoFirefox = "/usr/bin/firefox";
        String profileFirefox = "selenium";

        File pathToBinary = new File(caminhoFirefox);
        FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);

        ProfilesIni profile = new ProfilesIni();
        FirefoxProfile myprofile = profile.getProfile(profileFirefox);

        return new FirefoxDriver(ffBinary, myprofile);
    }

    public void close(@Disposes FirefoxDriver driver) {
        driver.quit();
    }

}

要使用它,我只是这样做:

@ApplicationScoped
public class Crawler {

    @Inject
    private FirefoxDriver driver;

    public void Crawl(){
        driver.get("http://siteimcrawling.com");
    }
}

为什么打开2个Firefox而不是一个?

0 个答案:

没有答案