0

我正在使用页面工厂设计模式,其中我实现了 Has-A关系波纹管类:

public class PaginationHelper 
{

    WebDriver driver;

    @FindBy(xpath="//li/button[@ng-click='next()']")    
    public WebElement nextPageButton;

    @FindBy(xpath="//li/button[@ng-click='goToLastPage()']")    
    public WebElement lastPageButton;

    @FindBy(xpath="//li/button[@ng-click='goToFirstPage()']")   
    public WebElement firstPageButton;

    @FindBy(xpath="//li/button[@ng-click='prev()']")    
    public WebElement previousPageButton;

    @FindBy(xpath="//ul[@class='pagination']/li[contains(@class,'ng-scope' )]") 
    public List<WebElement> allPages;

    public PaginationHelper(WebDriver driver)
    {

        PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), this);
        this.driver=driver;
    }

    public void clickNextPage()
    {
        nextPageButton.click();
    }

    public void clickLastPage()
    {
        lastPageButton.click();
    }

    public void clickFirstPage()
    {
        firstPageButton.click();
    }

    public void clickPreviousPage()
    {
        previousPageButton.click();
    }

    public List<WebElement> getAllPages()
    {
        return allPages;
    }
}

实现关系的另一个类:

import com.rconweb.helper.PaginationHelper;

public class RCON_D_ContactsPage 
{
    WebDriver driver;   
    PaginationHelper pagination;


    public RCON_D_ContactsPage(WebDriver driver)
    {

        PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), this);
        this.driver=driver;
        pagination =  new PaginationHelper(driver);
    }

    public void clickNextPage()
    {
        pagination.clickNextPage();
        //nextPageButton.click();
    }

    public void clickLastPage()
    {
        pagination.clickLastPage();
    }

    public void clickFirstPage()
    {
        pagination.clickFirstPage();
    }

    public void clickPreviousPage()
    {
        pagination.clickPreviousPage();
    }

    public List<WebElement> getAllPages()
    {
        return pagination.getAllPages();
    }

}

这就是我使用元素编写测试的方式

public class D_TC_Contacts_RcontactsTestCase extends DriverSetup
{
    RCONLoginPage loginpage;
    RCONHomePage homepage;
    RCON_D_ContactsPage contacts;


    @BeforeClass
    public void initilization() throws IOException
    {
        homepage = new RCONHomePage(driver);
        loginpage = new RCONLoginPage(driver);
        contacts = new RCON_D_ContactsPage(driver);
    }

    @Test
    public void pagesNavigation() throws IOException, InterruptedException
    {
        // Problem Statement 
        while(contacts.nextPageButton.isEnabled())
        {
            contacts.clickNextPage();
            CommonMethods.waitUntilLoaderGetInvisible(driver);
            TakeScreenshot.passedScreenShot("Next Page");
            LogWriter.logger.info("Clicked Next Page"); 
        }

        while(contacts.previousPageButton.isEnabled())
        {
            contacts.clickPreviousPage();
            CommonMethods.waitUntilLoaderGetInvisible(driver);
            TakeScreenshot.passedScreenShot("Previous Page");
            LogWriter.logger.info("Clicked Previous Page"); 
        }

        while(contacts.lastPageButton.isEnabled())
        {
            contacts.clickLastPage();
            CommonMethods.waitUntilLoaderGetInvisible(driver);
            TakeScreenshot.passedScreenShot("Last Page");
            LogWriter.logger.info("Clicked Last Page"); 
        }

        while(contacts.firstPageButton.isEnabled())
        {
            contacts.clickFirstPage();
            CommonMethods.waitUntilLoaderGetInvisible(driver);
            TakeScreenshot.passedScreenShot("First Page");
            LogWriter.logger.info("Clicked First Page");    
        }

    }

}

我的问题是,是否有可能或有一种方法可以访问PaginationHelper类中的类变量D_TC_Contacts_RcontactsTestCase而不在类中创建PaginationHelper类对象D_TC_Contacts_RcontactsTestCase

4

0 回答 0