Webdriver C#如何使用多个浏览器设置驱动程序超时
希望在这里找到我的答案,我花了大半个星期的时间试图自己解决这个问题,但我无法解决我的问题。有一点背景,我对webdriver的C#和NUnit测试还不熟悉,我正在尝试为我工作的公司创建一套回归套装。我们有一些与易趣高度集成的产品,因此在测试中,我需要单击一个按钮进入易趣登录页面,然后我需要登录。看起来很简单(至少我是这么想的)。我遇到的问题是每次点击易趣登录页面FF超时。我目前有我的测试设置在多个浏览器中运行,chrome和IE正在通过(它们也挂起了一点),但FF从未通过 这对我来说很奇怪,因为在这个测试的早些时候,我去ebay并成功登录。但是,当我必须将我的公司帐户链接到易趣帐户时,这个登录页面将永远占用我的时间。我知道我们将一些独特的令牌传递给ebay以链接帐户,我认为这是导致加载时间过长的原因 因此FF的故障总是相同的,在60秒后超时。我读过其他类似的问题()有一些解决方案我感兴趣的是将驱动程序超时设置为大于60秒。我不知道如何在多浏览器设置中实现这一点Webdriver C#如何使用多个浏览器设置驱动程序超时,c#,firefox,selenium,webdriver,nunit,C#,Firefox,Selenium,Webdriver,Nunit,希望在这里找到我的答案,我花了大半个星期的时间试图自己解决这个问题,但我无法解决我的问题。有一点背景,我对webdriver的C#和NUnit测试还不熟悉,我正在尝试为我工作的公司创建一套回归套装。我们有一些与易趣高度集成的产品,因此在测试中,我需要单击一个按钮进入易趣登录页面,然后我需要登录。看起来很简单(至少我是这么想的)。我遇到的问题是每次点击易趣登录页面FF超时。我目前有我的测试设置在多个浏览器中运行,chrome和IE正在通过(它们也挂起了一点),但FF从未通过 这对我来说很奇怪,因为
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(ChromeDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
public class UnitTest1<TWebDriver> where TWebDriver: IWebDriver, new()
{
PTGeneral General;
[TestFixtureSetUp]
public void SetUp()
{
General = new PTGeneral();
General.Driver = new TWebDriver();
}
如果您想了解更多信息,我将非常感谢您的帮助,前提是我理解您的要求;)
感谢大家的阅读,这个社区太棒了
还在为这件事挣扎。如果有帮助,下面是错误消息
------ Run test started ------
NUnit VS Adapter 2.0.0.0 executing tests is started
Loading tests from C:\Users\jburns\documents\visual studio 2013\Projects\PTTest\PTTest\bin\Debug\PTTest.dll
Run started: C:\Users\jburns\documents\visual studio 2013\Projects\PTTest\PTTest\bin\Debug\PTTest.dll
TearDown failed for test fixture PTTest.UnitTest1<ChromeDriver>
The HTTP request to the remote WebDriver server for URL http://localhost:64706/session/0186901c828d3a1ad7523ecd41dedf9a/element timed out after 60 seconds.
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.FindElement(String mechanism, String value)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(String xpath)
at OpenQA.Selenium.By.<>c__DisplayClasse.<XPath>b__c(ISearchContext context)
at OpenQA.Selenium.By.FindElement(ISearchContext context)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
at PTTest.PTGeneral.IsElementPresent(By by) in c:\Users\jburns\Documents\Visual Studio 2013\Projects\PTTest\PTTest\PTGeneral.cs:line 42
at PTTest.PTGeneral.EmailCleanUP() in c:\Users\jburns\Documents\Visual Studio 2013\Projects\PTTest\PTTest\PTGeneral.cs:line 105
at PTTest.UnitTest1`1.TearDown() in c:\Users\jburns\Documents\Visual Studio 2013\Projects\PTTest\PTTest\UnitTest1.cs:line 29
TearDown failed for test fixture PTTest.UnitTest1<FirefoxDriver>
这起了作用,使我的考试通过了。但我仍然需要一个在多个浏览器上运行的解决方案,因为我不想在有办法加载页面时维护两个不同的项目 然后,解决方案是在每次打开新页面时使用等待方法 在导航到每个新页面后放置此方法:
public void WaitForPageLoading(int secondsToWait = 600)
{
Stopwatch sw = new Stopwatch();
sw.Start();
try
{
while (sw.Elapsed.TotalSeconds < secondsToWait)
{
var pageIsReady = (bool)((IJavaScriptExecutor)Driver).ExecuteScript("return document.readyState == 'complete'");
if (pageIsReady)
break;
Thread.Sleep(100);
}
}
catch (Exception)
{
Driver.Dispose();
throw new TimeoutException("Page loading time out time has passed " + secondsToWait + " seconds");
}
finally
{
sw.Stop();
}
}
public void waitforpageload(int secondsToWait=600)
{
秒表sw=新秒表();
sw.Start();
尝试
{
同时(sw.Essed.TotalSeconds
请显示如何导航到此加载时间较长的页面。显示你是如何点击按钮的。我找到了解决这个问题的方法。我能够绕过它的方法是增加SetPageLoadTimeout()。然后,我从触发页面加载的按钮捕获链接,并通过gotour()调用调用新页面,该调用遵循SetPageLoadTimeout()设置的超时。
General.Driver = new FirefoxDriver(new FirefoxBinary(), new FirefoxProfile(), TimeSpan.FromSeconds(180));
public void WaitForPageLoading(int secondsToWait = 600)
{
Stopwatch sw = new Stopwatch();
sw.Start();
try
{
while (sw.Elapsed.TotalSeconds < secondsToWait)
{
var pageIsReady = (bool)((IJavaScriptExecutor)Driver).ExecuteScript("return document.readyState == 'complete'");
if (pageIsReady)
break;
Thread.Sleep(100);
}
}
catch (Exception)
{
Driver.Dispose();
throw new TimeoutException("Page loading time out time has passed " + secondsToWait + " seconds");
}
finally
{
sw.Stop();
}
}