asp.net – 如何使我的硒测试不那么脆弱?
我们使用Selenium来测试我们的ASP.NET应用程序的UI层。许多测试用例测试跨越几页的较长流程。
我发现测试非常脆弱,不仅仅是通过实际更改页面的代码更改,而且还通过无害重构(如重命名控件)(因为我需要将控件的clientID传递给Selenium的Click方法等)或替换具有中继器的gridview。因此,我发现自己在我的测试用例中“浪费”时间更新字符串值,以修复断开的测试。 有没有办法编写更可维护的硒测试?还是更好的网络UI测试工具? 编辑添加: 解决方法
我发现PageObject模式非常有帮助。
http://code.google.com/p/webdriver/wiki/PageObjects 更多信息: 可能一个很好的方法就是逐步重构你的测试用例。 我用同样的场景你有硒c# 这是我的代码如何: 测试方法看起来像这样的东西 [TestMethod] public void RegisterSpecialist(UserInfo usrInfo,CompanyInfo companyInfo) { var RegistrationPage = new PublicRegistrationPage(selenium) .FillUserInfo(usrInfo) .ContinueSecondStep(); RegistrationPage.FillCompanyInfo(companyInfo).ContinueLastStep(); RegistrationPage.FillSecurityInformation(usrInfo).ContinueFinishLastStep(); Assert.IsTrue(RegistrationPage.VerifySpecialistRegistrationMessagePayPal()); selenium.WaitForPageToLoad(Resources.GlobalResources.TimeOut); paypal.LoginSandboxPage(usrInfo.sandboxaccount,usrInfo.sandboxpwd); Assert.IsTrue(paypal.VerifyAmount(usrInfo)); paypal.SubmitPayment(); RegistrationPage.GetSpecialistInformation(usrInfo); var bphome = new BPHomePage(selenium,string.Format(Resources.GlobalResources.LoginBPHomePage,usrInfo.AccountName,usrInfo.Password)); Assert.IsTrue(bphome.VerifyPageWasLoaded(usrInfo)); Assert.IsTrue(bphome.VerifySpecialistProfile()); bphome.Logout(); } 页面对象将是这样的 public class PublicRegistrationPage { public ISelenium selenium { get; set; } #region Constructors public PublicRegistrationPage(ISelenium sel) { selenium = sel; selenium.Open(Resources.GlobalResources.PublicRegisterURL); } #endregion #region Methods public PublicRegistrationPage FillUserInfo(UserInfo usr) { selenium.Type("ctl00_cphComponent_ctlContent_wizRegister_tUserFirstName",usr.FirstName); selenium.Type("ctl00_cphComponent_ctlContent_wizRegister_tUserLastName",usr.LastName); selenium.Select("ctl00_cphComponent_ctlContent_wizRegister_ddlUserCountry",string.Format("label={0}",usr.Country )); selenium.WaitForPageToLoad(Resources.GlobalResources.TimeOut); selenium.Type("ctl00_cphComponent_ctlContent_wizRegister_tUserEmail",usr.Email ); selenium.Type("ctl00_cphComponent_ctlContent_wizRegister_tUserDirectTel",usr.DirectTel); selenium.Type("ctl00_cphComponent_ctlContent_wizRegister_tUserMobile",usr.Mobile); return this; } } 希望这可以帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – 如何在OwinContext的Asp.net MVC5 Controll
- asp.net-core-mvc – 创建多个dbcontexts的MVC 6 EF7 RC1
- asp.net-mvc – 如何在ASP.NET应用程序中设置S-MaxAge Cach
- asp.net – Response.End()和Response.Flush()之间的差异
- asp.net core系列 63 领域模型架构 eShopOnWeb项目分析 上
- ASP.Net Forms身份验证在10分钟后注销用户
- asp.net-mvc – 在表单提交时传递整个模型
- asp.net-mvc – 如何使用ASP.NET MVC实现自定义缓存提供程序
- ASP.NET – LINQ的优势
- 使用asp.net用户控件时我在哪里放JavaScript?