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 – IE10 SCRIPT5009:’__doPostBack’未定义
- asp.net – Linq更新记录
- asp.net-mvc – ASP.NET MVC – 用于ICollection的EditorTe
- asp.net-mvc – ASP.NET MVC JavaScript路由
- ASP.NET MVC与Webforms与HTTP处理程序(.ashx) – 哪个是最轻
- asp.net-mvc – 从扩展Apicontroller的MVC控制器返回Json
- asp.net – 如何打破VB.NET中的“if”块
- asp.net-mvc – 如何在单个视图中使用两个表单
- 如何确定ASP.NET应用程序域的生命周期
- asp-classic – Request.BinaryRead(Request.TotalBytes)抛
- asp.net – 未捕获TypeError:无法读取未定义的属
- asp.net – precompiledApp.config的目的是什么?
- asp.net-mvc – 如何删除SimpleMembership用户?
- asp.net-mvc – 将Viewmodel数据保存到ASP.NET M
- asp.net-mvc – 什么是ASP.Net MVC查看引擎?
- asp.net – 有没有比升级到Visual Studio 2010 U
- asp.net-core – 如何使用带有IdentityServer4的
- asp.net – 实体框架删除子对象
- asp.net-mvc – 发现MVC项目中是否使用views / p
- 每个“HttpRequest”在ASP.NET中都有自己的线程吗
