2017-02-28 38 views
0

我创建了一个带有相对路径的jar(意思是我给了geckodriver里面的资源并映射了它),但问题是Firefox启动但url没有加载。我需要它在运行多个操作系统的多个系统上运行。谁能帮忙?URL未加载Firefox(Selenium)

import com.relevantcodes.extentreports.ExtentReports; 
import com.relevantcodes.extentreports.ExtentTest; 
import com.relevantcodes.extentreports.LogStatus; 
import org.junit.Test; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.firefox.FirefoxProfile; 
import org.testng.annotations.BeforeTest; 

import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.Date; 
import java.util.List; 


public class Maintest { 

    public static FirefoxDriver driver; 
    //public static ChromeDriver driver; 
    public static String downloadPath = "/home/user/Desktop/Downloads"; 
    private static ExtentReports reports; 


    @BeforeTest 

    public static void createDriver() { 
     System.setProperty("webdriver.firefox.marionette", "/home/user/Desktop/geckodriver"); 
     driver = new FirefoxDriver(FirefoxDriverProfile()); 
     driver.manage().window().maximize(); 
    } 

    public static FirefoxProfile FirefoxDriverProfile() { 
     FirefoxProfile profile = new FirefoxProfile(); 
     profile.setPreference("browser.download.folderList", 2); 
     profile.setPreference("browser.download.manager.showWhenStarting", false); 
     profile.setPreference("browser.download.dir", downloadPath); 
     profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream"); 
     profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv, application/pdf,application/octet-stream"); 
     profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf,application/x-pdf, application/pdf,application/vnd.fdf,application/vnd.ppdf, application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf, application/vnd.cups-pdf, application/foxit"); 
     profile.setPreference("browser.helperApps.neverAsk.openFile", 
       "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml/application/pdf"); 
     profile.setPreference("browser.helperApps.neverAsk.saveToDisk", 
       "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml/application/pdf"); 
     profile.setPreference("browser.helperApps.alwaysAsk.force", false); 
     profile.setPreference("pdfjs.disabled", true); 
     profile.setPreference("plugin.scan.Acrobat", "99.0"); 
     profile.setPreference("plugin.scan.plid.all", false); 
     profile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf"); 
     profile.setPreference("browser.download.manager.alertOnEXEOpen", false); 
     profile.setPreference("browser.download.manager.focusWhenStarting", false); 
     profile.setPreference("browser.download.manager.useWindow", false); 
     profile.setPreference("browser.download.manager.showAlertOnComplete", false); 
     profile.setPreference("browser.download.manager.closeWhenDone", false); 
     return profile; 
    } 

    @Test 

    public static void bridge(List<String> selectedList) throws Exception { 
     createDriver(); 
     System.out.println("###############"+new Date()+"###############\n\n"); 
     DateFormat format = new SimpleDateFormat("dd-MM-yyyy"); 
     Date date = new Date(); 
     String dateTime = format.format(date); 
     reports = new ExtentReports("/home/user/Desktop/Regression Results-"+dateTime+".html", true); 
     driver.get("http://sitename"); 
+0

它与其他浏览器一起工作吗? – balazs630

+0

nope。网址无法在任何浏览器加载 –

+0

请看看上面的代码。它在我开发脚本的机器上工作,但不能在其他机器上使用Firefox 49及以上版本。使用jar文件来运行它。 –

回答

0

已知的问题是,当您使用geckodriver较低的版本出现,一个多补充检查壁虎驱动程序是否与您的特定环境兼容与否。 您可以从https://github.com/mozilla/geckodriver/releases下载最新版本

+0

我正在使用最新的.. –

+0

你能提供更多关于你的环境的细节 – Abhishek

+0

intellij 16.3,gecko v0.14.0。能够运行它直到FF 48版本。它的整个网站使用硒和Java自动化。 FF 49,50和51不能正常工作。我需要它运行在运行不同os和firefox版本的不同机器上。 –