我想初始化我的对象并为每个页面类创建一次实例。这是用于 Java 中的测试 - Selenium

问题描述 投票:0回答:0

为了避免重复我的代码而不是在每次测试中都插入这些代码行,我想知道是否有一种有效/高效的方法,我将在类/页面中只使用一次。我想一次初始化对象。感谢您的协助! 这是我的代码:

公共类 ContributionTests 扩展 BaseTest {

@Test (priority = 1)
@Severity(SeverityLevel.CRITICAL)
@Description("Create a Contribution E2E, using only required fields, and validate the new creation contribution name")
public void tc1_CreateContribution() throws InterruptedException {

    MainPage mainPageGP = new MainPage(driver);
    AssetTabPage assetTabPage = new AssetTabPage(driver);
    UnderManagementAssetPage umap = new UnderManagementAssetPage(driver);
    ContributionTabPage ctp = new ContributionTabPage(driver);
    NewContributionFormPage ncp = new NewContributionFormPage(driver);
    NewCreatedContributionPage nccp = new NewCreatedContributionPage(driver);
    ExistingContributionPage ecp = new ExistingContributionPage(driver);

    mainPageGP.setMainTab("Assets");
    assetTabPage.selectUnderManagementTab();
    getSleep(500);
    assetTabPage.selectAsset("new Asset- Test on Edge");
    getSleep(500);
    umap.selectInnerTab("Contributions");

}

我还没有尝试任何东西,但希望在我的测试类中节省很多代码行。

此时,我在每次测试中插入这些initilizes:

    MainPage mainPageGP = new MainPage(driver);
    AssetTabPage assetTabPage = new AssetTabPage(driver);
    UnderManagementAssetPage umap = new UnderManagementAssetPage(driver);
    ContributionTabPage ctp = new ContributionTabPage(driver);
    NewContributionFormPage ncp = new NewContributionFormPage(driver);
    NewCreatedContributionPage nccp = new NewCreatedContributionPage(driver);
    ExistingContributionPage ecp = new ExistingContributionPage(driver);
java selenium-webdriver automated-tests instance
© www.soinside.com 2019 - 2024. All rights reserved.