Firefox驱动程序未在虚拟机

时间:2018-01-04 16:28:23

标签: selenium jenkins virtual-machine selenium-firefoxdriver

    1. resources I used : C# , Selenium , VS 2017, Jenkins , VM machine (windows 10) , Nunit v3.9, geckoDrive v19, firefox v56/57 

    2. I can execute firefox / chrome browser cases on local machine 

    3. I can execute chrome browser cases on VM machine 

    4. Issue : **I can Not execute firefox cases on VM machine and its throwing below error.** 
    **Error Message**

OpenQA.Selenium.WebDriverException:无法在http://localhost:50352/上启动驱动程序服务

TearDown:System.NullReferenceException:未将对象引用设置为对象的实例。

我在下面添加了几个代码,问题就是问题
堆栈跟踪

   at OpenQA.Selenium.DriverService.Start()
   at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(String geckoDriverDirectory, FirefoxOptions options, TimeSpan commandTimeout)
   at MPAutomation.Driver.Initialize(String browser) in D:\Workspace.Automation\MPproject\MPAutomation\Utility\Driver.cs:line 79
# code on this line : Instance = new FirefoxDriver(service.FirefoxBinaryPath, options, TimeSpan.FromSeconds(10));  
  at MPAutomation.BaseTest.Init() in D:\Workspace.Automation\MPproject\MPAutomation\Utils\BaseTest.cs:line 54
  #code here :  LoginPage.GoTo(Settings.BrowserType); # I am passing "Firefox"
--TearDown
   at MPAutomation.Driver.Close() in D:\Workspace.Automation\MPproject\MPAutomation\Utility\Driver.cs:line 117
   # Instance.Close();
   at MPAutomation.BaseTest.Cleanup() in D:\Workspace.Automation\MPproject\MPAutomation\Utils\BaseTest.cs:line 97


---------------------------------------------------------------------  

firefox实现在Driver.cs 中看起来像这样       - 我尝试使用各种版本的Firefox,但没有一个在VM上工作

else if(browser.Equals(Constant.Firefox))                           {
    // driver init from here 
                            FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(DrivePath);
                            service.FirefoxBinaryPath = DrivePath;
                            var profile = new FirefoxProfile();
                            profile.AcceptUntrustedCertificates = true;
                            var options = new FirefoxOptions();
                            options.AcceptInsecureCertificates = true;
                            options.Profile = profile;                
                            Instance = new FirefoxDriver(service.FirefoxBinaryPath, options, TimeSpan.FromSeconds(10));
                            Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

                            Utility.Logger.Write("***** Firefox Browser has been initialized now  *********");
                           }

           --------------------------------
    5. We have one certificate for firefox and which has already been taken care locally and on VM 

    6. I am not sure why automation is not able to start firefox on VM              

1 个答案:

答案 0 :(得分:0)

最后我们得到了这个问题的解决方案。

我们需要设置"沙箱级别"对于VM上的Firefox。

profile.setPreference(" security.sandbox.content.level",5);

https://github.com/mozilla/geckodriver/issues/466

https://wiki.mozilla.org/Security/Sandbox