我只是想知道如何解决这个问题。我需要自动化我公司网站。在那里,我需要浏览多个URL的多个网页。我曾与Page对象模型设计一起设计的混合架构。
我的要求是,说我有3个网址:
www.google.com www.yahoo.com Facebook的
上述所有的URL和它的测试数据,我会保持一个Excel工作表。我已经创建了三个不同的页面和三个不同的测试类。所以,我的问题清单如下:
执行流程需要实现应用的:
在Excel中保存的网址是不是好主意,
您需要参数化与TestCase的属性测试。
[TestCase("www.google.com")]
[TestCase("www.yahoo.com")]
[TestCase("www.facebook.com")]
public void WebPageTest(string site)
{
driver.Url(site);
//continue with the test.
}
看到这篇文章,以了解更多:https://github.com/nunit/docs/wiki/TestCase-Attribute
我建议你使用【类别】属性来分类你的测试用例。例如
[Test]
[Category("GoogleTest")]
public void googletest1()
{
}
[Test]
[Category("FBTest")]
public void fbtest1()
{
}
现在,在[设置]的方法,你可以根据类别加载的url,像
[SetUp]
public void testsetup()
{
#initialise driver
var category = TestContext.CurrentContext.Test.Properties.Keys;
if(category.Contains("GoogleTest"))
{
//category1 setup
}
else if(category.Contains("FBTest"))
{
//category2 setup
}
}
因此,使用这种方法就可以解决查询#2,即相关测试的网址已加载你,这样你就可以设置后,您的测试继续