在测试代码中硬编码测试数据
作者:网络转载 发布时间:[ 2012/9/12 9:13:14 ] 推荐标签:
从上面的代码中,你可以观察到,Post的属性,除了Settings属性以外,其他的属性都是从网页上直接读取的—当然是假设当前网页正在显示对应的文章。因此,要将基准数据库集成到自动化测试代码中来,只要实例化一个PostSettings变量好了。TestLibrary是 负责连接到Selenium-RC,并保存对应连接的类。下面的代码演示了这个思想:
public class TestLibrary
{
public UserHelper UserHelper { get; private set; }
public BlogHelper BlogHelper { get; private set; }
public CommentHelper CommentHelper { get; private set; }
public Blog DefaultBlog { get; private set; }
public Post DefaultPost { get; private set; }
public ISelenium Selenium { get; private set; }
public string SiteUrl { get; private set; }
public class Consts
{
public const string TimeToWaitForPageToLoad = "30000";
public const string AdminUserName = "administrator";
public const string AdminPassword = "0123456";
}
public TestLibrary(ISelenium selenium)
{
this.UserHelper = new UserHelper(this);
this.BlogHelper = new BlogHelper(this);
this.CommentHelper = new CommentHelper(this);
Selenium = selenium;
InitialDefaultSiteDate();
}
private void InitialDefaultSiteDate()
{
DefaultBlog = new Blog(this, "Default Test Blog", "default-test-blog", "Default Test Blog", Consts.AdminUserName);
DefaultPost = new Post(this, new PostSettings()
{
Title = "Default Test Post",
Permalink = "default-test-post",
Body = "This is for web site testing purpose.",
Tags = "Test",
PublishSetting = PostSettings.PublishSettings.PublishNow
},
DefaultBlog);
}
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11