什么是在系统测试与硒的工作时使用的Thread.Sleep另类? [英] What's the alternative to use Thread.Sleep when working with Selenium in system testing?

查看:163
本文介绍了什么是在系统测试与硒的工作时使用的Thread.Sleep另类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Selenium如下一个TestMethod的:

I have a TestMethod using Selenium as below:

 [TestMethod]
        public void ShouldSendPasswordReminder()
        {
            // go to loginregister url
            _fireFoxWebDriver.Navigate().GoToUrl(UkPaBaseUrl + "loginregister.aspx");
            Thread.Sleep(1000);

            // click the forgotten password
            _fireFoxWebDriver.FindElement(By.LinkText("Forgotten your password?")).Click();
            Thread.Sleep(1000);

            // enter your email address

            _fireFoxWebDriver.FindElement(By.Id("PasswordResetRequest1_PasswordResetRequest_Username"))
                .SendKeys("username.lastname@domain.com");
            Thread.Sleep(1000);

            // click submit
            _fireFoxWebDriver.FindElement(By.Id("PasswordResetRequest1_PasswordResetRequest_PasswordResetRequestSubmit")).Click();
            Thread.Sleep(5000);

            // assert
            Assert.IsTrue(_fireFoxWebDriver.Url.Contains("ThankYou"));
        }



正如你所看到的,我不得不叫了Thread.Sleep多次(因为页面可能需要一些时间来完成它做什么,由于JavaScript的,等等),每个动作之后,几乎因为硒似乎没有能够处理页面加载和延迟不像华廷。

As you can see, I'd have to call Thread.Sleep many times (because the page might take some time to finish what it does due to javascript, etc) almost after each action because Selenium doesn't seem to be able to handle page loads and delays unlike WatiN.

这使得代码相当丑陋,而不是非常可靠。

This makes the code rather ugly and not very much reliable.

什么是更好的方式来处理这样的场景?你写你的测试频繁的Thread.Sleep调用呢?

What's the better way to handle such scenarios? Do you write frequent Thread.Sleep calls in your tests as well?

谢谢,

推荐答案

您可以使用管理功能来设置你想要的基准线时间 FindElement()等待失败之前:

You could use the manage functionality to set the base line time you want FindElement() to wait for before failing:

_fireFoxWebDriver.Manage()
                 .Timeouts()
                 .ImplicitlyWait(TimeSpan.FromSeconds(1000));

这篇关于什么是在系统测试与硒的工作时使用的Thread.Sleep另类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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