Suggestions for getting Selenium to play nice with Bootstrap modal fade?

后端 未结 7 1124
[愿得一人]
[愿得一人] 2021-02-05 19:45

I\'m working to live life the BDD way. I\'m using Cucumber (with Selenium) and happen to be using Twitter Bootstrap modals in my application.

While running Cucumber tes

7条回答
  •  梦谈多话
    2021-02-05 20:05

    I solved it this way (using c#). It is fast and hasn't failed once.

    public static void WaitForModal(this RemoteWebDriver driver)
    {
        using (driver.NoImplicitWait())
        {
            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
            wait.Until(d => d.FindElements(By.ClassName("modal-backdrop").Count == 0);
        }
    }
    

    NoImplicitWait is used to temporarily disable the driver implicit wait.

    public static NoImplicitWait NoImplicitWait(this IWebDriver driver)
    {
        return new NoImplicitWait(driver);
    }
    
    public sealed class NoImplicitWait : IDisposable
    {
        private readonly IWebDriver _driver;
    
        public NoImplicitWait(IWebDriver driver)
        {
            _driver = driver;
            _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(0));
        }
    
        public void Dispose()
        {
            _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
        }
    }
    

提交回复
热议问题