针对大量网站运行相同的测试 [英] Running same tests against a large number of websites

查看:159
本文介绍了针对大量网站运行相同的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要针对70多个网站运行相同的测试,这些网站功能相同,但皮肤不同。但是,它们都通过不同的URL访问。

I have a need to run the same tests against over 70 websites which are all functionally the same but have different skins. They are all accessed through different URLs however.

使用TestNG和Java,将URL传递给测试的有效方法是什么,以便我可以:
a)针对每个站点运行每个测试报告同一
b)并行执行测试以节省时间(未来需要)

Using TestNG and Java, What would be an efficient way to pass the URLs to the tests so that I can: a) run each test against each site and report on same b) execute tests in parallel to save time (future need)

我想以一种格式存储URL,使其暴露于最终用户可由他们配置。理想情况下,这将在.csv中,或者在testng.xml文件中。我在考虑@DataProvider或@Factory,但我不确定如何以有效和可维护的方式使用这些来从外部源获取参数,或者在我当前模型中哪些方法最适合放置?我遇到的困难是我不想将数据必然传递到@Test,而是一次传入一个值(一个url)并对所有@Test注释方法运行。

I want to store the URLs in a format such that it is exposed to end users and configurable by them. This would ideally be in a .csv or alternatively, as in the testng.xml file. I am thinking either @DataProvider or @Factory but am unsure how to use these in an efficient and maintainable way to take parameters from an external source or where in my current model such methods would be best placed? The difficulty I have is that I don't want to pass the data necessarily into @Test's, rather pass in one value at a time (a url) and run against all @Test annotated methods.

我目前的简单设置如下:

My current simple setup is as follows:

testngxml:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite1" verbose="1">
<test name="FindARouteTest">
    <parameter name="number" value="1"/>
    <parameter name="from" value="LONDON"/>
    <parameter name="to" value="GLASGOW"/>
    <parameter name="emailAddress" value="test@example.co.uk"/>
    <classes>
        <class name="acceptancetests.EndToEndTest">
        </class>
    </classes>
</test>

我的验收测试:

public class EndToEndTest extends DriverBase{

private HomePage home;
private String url;

@Factory(dataProvider = "urls", dataProviderClass = URLProvider.class)
public EndToEndTest(String url) {
    this.url = url;
}


@BeforeSuite
public void stuff(){
    newDriver();
}


@BeforeClass
public void setup(){
    home = new HomePage(driver, url);
}

@Test (priority = 1)
@Parameters({"from","to"})
public void searchForARoute(String from, String to) throws InterruptedException {
    home.selectWhereFrom(from);
    home.selectWhereTo(to);
    //some assertions...

我的PageObject:

My PageObject:

public class HomePage extends SeleniumBase {

public HomePage(WebDriver driver, String url) {
    super(driver, url);
    try {
        visit(url);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    driver.manage().window().maximize();
}

public void someMethodOrOther(){
//some methods...

我的Selenium方法基页:

My Selenium Methods BasePage:

public class SeleniumBase implements Config {

public WebDriver driver;
public String url;

public SeleniumBase(WebDriver driver) {
    this.driver = driver;
    this.url = url;
}

public void visit() throws MalformedURLException {
    driver.get(url);
} //more methods...

我的驱动程序基页:

public class DriverBase implements Config {

public static WebDriver driver;
public static String url;

    protected void newDriver() {
        if (host.equals("localhost")) {
            if (browser.equals("firefox")) {
                System.setProperty("webdriver.gecko.driver",
                        System.getProperty("user.dir") + "\\drivers\\geckodriver.exe");
                FirefoxProfile fp = new FirefoxProfile();
//more stuff

URL提供者类:

public class URLProvider {

@DataProvider(name = "urls")
public static Object[][] dataProviderMethod()
{
    return new Object[][] {{"http://siteone.com"},
                            {"http://sitetwo.com"},
                            {"http://sitethree.com"}
    };
}
}

最后,一个目前只持有BaseUrl的Config:

Finally, a Config which currently holds only a BaseUrl:

public interface Config {

String baseUrl = System.getProperty("baseUrl", 
String browser = System.getProperty("browser", "chrome");
String host = System.getProperty("host", "localhost");

}


推荐答案

您可以在构造函数上使用@Factory注释来测试类EndToEndTest和给它一个数据提供者。

You can use the @Factory annotation on the constructor for test class EndToEndTest and give it a dataprovider.

private String url;

@Factory(dataProvider = "urls", dataProviderClass = URLProvider.class)
public EndToEndTest(String url) {
  this.url = url;
}

您需要提供URL数据提供程序类的实现来访问excel或您想要的任何文件并返回Object [] []。

You need to provide the implementation of the URL data provider class to access the excel or whatever file you want and return an Object[][].

需要修改HomePage和SeleniumBase的构造函数以传入u你从@BeforeClass方法调用的rl。

Need to modify the constructors of HomePage and SeleniumBase to pass in the url which you are calling from your @BeforeClass method.

这应该为每个url字符串的这个测试类创建一个单独的实例并调用@Test方法。

This should create a separate instance for this test class for every url string and call the @Test methods.

如果您需要传递的数据多于字符串URL,则可以使用对象。正如我可以看到你在testng.xml中为方法传递了4个参数。

If you need to pass in more data than a string URL you can use an object instead. As I can see your passing 4 parameters in your testng.xml for a method.

并行性应该非常简单,猜测你想要运行所有的@Test方法单个线程中的给定URL。并行选项是类。

Parallelism should be pretty simple, guessing you would want to run all the @Test methods for a given url in a single thread. The parallel option would be "classes".

这篇关于针对大量网站运行相同的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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