TestStack / TestStack.Seleno

Seleno helps you write automated UI tests in the right way by implementing Page Objects and Page Components and by reading from and writing to web pages using strongly typed view models.
http://teststack.github.com/TestStack.Seleno/
MIT License
180 stars 60 forks source link

Setting delay to let animation complete #210

Closed harihara6 closed 9 years ago

harihara6 commented 9 years ago

I am trying to test a page where a bootstrap modal is show asking for confirmation to delete. Modal will have a fade animation effect which makes the test fail saying the element is not visible.I have tried few things,

1 Thread.Sleep() - Its working until the button click on modal. But the next line (code given below) is not returning the CCPage. It takes some time after delete for the page to load. But it is not waiting for the given 10 secs to allow the page load.

return this.Navigate.To(By.XPath("id('delete')/div/div/div[3]/button"), TimeSpan.FromSeconds(10));

2 Code from somewhere over internet

public void UntilAnimationIsDone(string elementId, int timeoutInSeconds = ImplicitWaitInSeconds)
        {
            Until(driver =>
             {
                 var javaScriptExecutor = (IJavaScriptExecutor)driver;
                 var isAnimated = javaScriptExecutor
                     .ExecuteScript(string.Format("return $('#{0}').is(':animated')", elementId))
                      .ToString().ToLower();
                 return !bool.Parse(isAnimated);
             }, timeoutInSeconds);
        }

  public void Until(Func<IWebDriver, bool> waitCondition, int timeoutInSeconds = ImplicitWaitInSeconds)
        {
            IWebDriver driver = Host.Instance.Application.Browser;
            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
            wait.Until(waitCondition);
        }

3 Some other approach

 public void AnimWait(string elementId)
        {
            IWebDriver drv = Host.Instance.Application.Browser;
            var wait = new WebDriverWait(drv, TimeSpan.FromSeconds(5));
            wait.Until(driver => drv.FindElement(By.Id(elementId)));
        }

But these 2 approaches are not working. And am not sure if i am initiating driver correctly. Please help out.

harihara6 commented 9 years ago

Now this is giving stable results

IWebDriver driver = Host.Instance.Application.Browser;
 WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3));
 wait.Until(t => t.FindElement(By.Id("delete")).GetAttribute("class")=="modal fade in");

wait until the class changes to modal fade in from modal fade Any better ideas are appreciated.