[英]Selenium tests run on local machine but not through jenkins
When running Selenium tests with C# in Visual Studio on my local machine the tests run fine and all pass. 在本地计算机上的Visual Studio中使用C#运行Selenium测试时,测试运行正常且全部通过。 However when I try to run them on jenkins they fail.
但是,当我尝试在詹金斯上运行它们时,它们将失败。 If I use FireFox then Jenkins runs fine.
如果我使用FireFox,那么Jenkins可以正常运行。 The problem with that though is that my boss wants to use IE because that's what our company uses most.
但是,问题在于我的老板想使用IE,因为这是我们公司最常用的。
Here is the code that is failing to run: 这是无法运行的代码:
[TestInitialize]
public void openBrowser()
{
//Start Opening browser
var options = new InternetExplorerOptions()
{
InitialBrowserUrl = baseURL,
IntroduceInstabilityByIgnoringProtectedModeSettings = true,
IgnoreZoomLevel = true,
EnableNativeEvents = false
};
string IE_DRIVER_PATH = @"C:\Users\eedward7\Desktop\Selenium";
driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl(this.baseURL);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("ctl00_ContentPlaceHolder1_Login1_UserName")));
driver.FindElementById("ctl00_ContentPlaceHolder1_Login1_UserName").SendKeys(userID);
driver.FindElementById("ctl00_ContentPlaceHolder1_Login1_Password").SendKeys(password);
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("ctl00_ContentPlaceHolder1_Login1_LoginButton")));
driver.FindElementById("ctl00_ContentPlaceHolder1_Login1_LoginButton").Click();
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("ctl00_TreeView1t6")));
}
Here is the Jenkins error message: 这是詹金斯(Jenkins)错误消息:
Initialization method Selenium.Tests.openBrowser threw exception.
初始化方法Selenium.Tests.openBrowser引发异常。 OpenQA.Selenium.WebDriverException: OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:61076/session timed out after 60 seconds.
OpenQA.Selenium.WebDriverException:OpenQA.Selenium.WebDriverException:对URL http:// localhost:61076 / session的远程WebDriver服务器的HTTP请求在60秒后超时。 ---> System.Net.WebException: The operation has timed out.
---> System.Net.WebException:操作已超时。
And Last but not least the Stacktrace: 最后但并非最不重要的Stacktrace:
at System.Net.HttpWebRequest.GetResponse() at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) --- End of inner exception stack trace --- at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) 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.IE.InternetExplorerDriver..ctor(String internetExplorerDriverServerDirectory, InternetExplorerOptions options) at Selenium.Tests.openBrowser() in c:\\Users\\eedward7\\Desktop\\Selenium\\Selenium\\UnitTest1.cs:line 50
在System.Net.HttpWebRequest.GetResponse()在OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest请求)-内部异常堆栈跟踪的结尾-在OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest请求)在OpenQA处的OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(在Command处的OpenQA.Selenium.Remote.Remote。 OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor,ICapabilities requiredCapabilities)处于OpenQA.Selenium.IE.Internet.r.InternetExplorerDriver..ctor(String InternetExplorerDriverServerDirector.String.Selenium.Remote.Remote。 c:\\ Users \\ eedward7 \\ Desktop \\ Selenium \\ Selenium \\ UnitTest1.cs中的Tests.openBrowser():第50行
If anyone has any suggestions that would be amazing because I am at a loss right now on what to do. 如果有人提出任何建议,那将是令人惊讶的,因为我现在在做什么方面无所适从。
Try chromeDriver with these options 使用以下选项尝试chromeDriver
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("test-type");
chromeOptions.AddArguments("no-sandbox");
new ChromeDriver(chromeOptions);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.