如何通过Selenium和Webdriver提高执行速度 [英] How to increase the execution speed through Selenium and Webdriver

查看:789
本文介绍了如何通过Selenium和Webdriver提高执行速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

脚本执行期间的测试速度非常慢,不知道原因.

Test is very slow during execution of the script without knowing the reason.

这是我的脚本:

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);
}

任何建议如何使测试更快?

Any suggestion how to make the test faster ?

推荐答案

使脚本/程序更快的简单步骤是:

A simple step to make your script/program faster would be to:

  • ImplicitWait 的所有实例删除为:
    • 您正在广泛使用 WebDriverWait ,即明确等待
    • Remove all the instances of ImplicitWait as:
      • You are extensively using WebDriverWait i.e. Explicit Wait

      按照 显式和隐式等待 :

      警告:请勿混合使用隐式和显式等待.这样做可能导致无法预测的等待时间.例如,将隐式等待设置为10秒,将显式等待设置为15秒,则可能导致20秒后发生超时.

      WARNING: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example setting an implicit wait of 10 seconds and an explicit wait of 15 seconds, could cause a timeout to occur after 20 seconds.

      这篇关于如何通过Selenium和Webdriver提高执行速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆