2016-06-24 12 views
1

SeleniumテストでPhantomJSドライバを使用しようとしましたが、WebサイトにログインしないようにFirefoxプロファイルを回復することはできません。 これは私のコードです:SeleniumのFirefoxプロファイルでPhantomJSドライバを使用できません

import static org.junit.Assert.fail; 

import java.util.concurrent.TimeUnit; 

import org.junit.After; 
import org.junit.Before; 
import org.junit.Test; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxProfile; 
import org.openqa.selenium.firefox.internal.ProfilesIni; 
import org.openqa.selenium.phantomjs.PhantomJSDriver; 
import org.openqa.selenium.remote.DesiredCapabilities; 

public class Stackoverflow { 
    private WebDriver driver; 
    private String baseUrl; 
    private StringBuffer verificationErrors = new StringBuffer(); 

    @Before 
    public void setUp() throws Exception { 
     System.setProperty("phantomjs.binary.path", System.getProperty("user.dir") + "/lib/phantomjs-2.1.1-windows/bin/phantomjs.exe"); 
     DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); 
     driver = new PhantomJSDriver(capabilities); 
     driver.manage().window().maximize(); 
     baseUrl = "http://stackoverflow.com/"; 
     driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
    } 

    @Test 
    public void testStackoverflow() throws Exception { 
     driver.get(baseUrl); 
    } 

    @After 
    public void tearDown() throws Exception { 
     driver.quit(); 
     String verificationErrorString = verificationErrors.toString(); 
     if (!"".equals(verificationErrorString)) { 
      fail(verificationErrorString); 
     } 
    } 
} 

あなたはどのようにPhantomJSドライバを設定する方法を教えてもらえますか?

答えて

0

PhantomJSでFirefoxプロファイルを使用しようとしているため、PhantomJSでFirefoxプロファイルを使用することはできません... PhantomJSはFirefoxではありません。どのように動作すると思われましたか? phantomjsドライバのパスを設定するための

+0

を、しかし、私は、Firefoxプロファイルなどを使用して解決策があるかどうか尋ねます。 – Steefler35

0

使用このコード、これを使用して、私はあなたがすべての問題直面した場合に知らせて:私はそれはもちろん不可能であることを知っている

File file = new File("E:\\software and tools\\phantomjs-2.1.1-windows\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");    
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());   

OR

System.setProperty("phantomjs.binary.path", "E:\\software and tools\\phantomjs-2.1.1-windows\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");  
WebDriver driver = new PhantomJSDriver(); 
関連する問題