2

我敢肯定,有经验的 Java 开发人员可以很快回答这个问题。但是由于我对 Java 不太熟悉,所以我不知道如何在 Java 中找到 Selenium 的 @Config 部分。如果我可以有一个配置文件或类,我可以将数据(浏览器、网站等)放在其中,另一方面是测试文件,那将是最佳的。
下面是一个测试文件的例子:

package com.example_test.selenium;

import io.ddavison.conductor.Browser;
import io.ddavison.conductor.Config;
import io.ddavison.conductor.Locomotive;
import org.junit.Test;

@Config(
        browser = Browser.CHROME,
        url     = "http://example.com"
)

public class test_a_Home extends Locomotive {
    @Test
    public void testifExists() {
        validatePresent(site_a_Home.EL_NEWCUSTOMERBANNER);
    }
}

现在我想要一个名为tests.java 的单独文件,我可以在其中调用“test_a_Home”函数。如果我尝试一下

package com.example_test.selenium;

public class tests {
    test_a_Home test = new test_a_Home();

    test.testifExists();

}

我收到错误消息,“testifExists()”无法解决。
我尝试更改public void testifExists()topublic int testifExists()并尝试使用int res = test.testifExists();in调用它,class tests但这也不起作用,因为我收到 error java.lang.Exception: Method testNewCustomersBannerExists() should be void
如果有人可以帮助我,我会很高兴。如果您需要更多信息,请随时提及。谢谢你。

4

1 回答 1

1

如果您希望您的设计是这样的,那么您需要这样组织您的测试:

public class BasePage {
    public Locomotive test;
    public BasePage(Locomotive baseTest) {
        test = baseTest;
    }
}

public class test_a_Home extends BasePage {
    public test_a_Home(Locomotive baseTest) {
        super(baseTest);
    }

    public void testifExists() {
        test.validatePresent(site_a_Home.EL_NEWCUSTOMERBANNER);
    }
}

然后你的测试类,我建议也创建一个基类:

@Config(
    browser = Browser.CHROME,
    url     = "http://example.com"
)
public class BaseTest extends Locomotive {}

然后你的测试类:

public class tests extends BaseTest {
    test_a_Home test = new test_a_Home(this);

    @Test
    public void testHomePage() {
        test.testIfExists();
    }
}

您还声明状态:

我不知道如何在 Java 中获取 Selenium 的 @Config 部分。

请确保您知道,使用 Conductor 会将您从 Selenium API 中抽象出来。它只是将它包装起来。 @Config不属于 Selenium,它属于 Conductor。

于 2015-11-06T13:38:11.663 回答