如何通过Selenium和Webdriver提高执行速度
在不知道原因的情况下,脚本执行期间的测试速度非常慢。
这是我的脚本:
driver.Navigate().GoToUrl(url); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
driver.FindElement(By.LinkText("Register Here")).Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(
SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(
(By.XPath("//div[@class='loader-wrapper ng-trigger ng-trigger-visibilityChanged ng-animating']"))));
driver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Organization Type'])[2]/following::select[1]")).Click();
new SelectElement(driver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Organization Type'])[2]/following::select[1]"))).SelectByText("Hospital");
driver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Organization Type'])[2]/following::button[1]")).Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(
SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(
(By.XPath("//div[@class='loader-wrapper ng-trigger ng-trigger-visibilityChanged ng-animating']"))));
driver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Phone Number'])[1]/following::button[1]")).Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(
SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(
(By.XPath("//div[@class='loader-wrapper ng-trigger ng-trigger-visibilityChanged ng-animating']"))));
try
{
Assert.AreEqual("Title is Required.", driver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Title'])[1]/following::span[1]")).Text);
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
有什么建议可以使测试更快吗?
回答:
一个使脚本/程序更快的简单步骤是:
- 删除所有 实例为:
- 您正在广泛使用 即
根据
的文档:
:请勿混合使用隐式和显式等待。这样做可能导致无法预测的等待时间。例如,将隐式等待设置为10秒,将显式等待设置为15秒,则可能导致20秒后发生超时。
以上是 如何通过Selenium和Webdriver提高执行速度 的全部内容, 来源链接: utcz.com/qa/431295.html