I'm using Page Factory design pattern where I have implemented Has-A relation bellow classes :
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;
}
}
Another class where relation implemented :
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();
}
}
And this is how I'm using the element to write the test
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");
}
}
}
My Question is, Is it possible or there is a way to access PaginationHelper
class variable in D_TC_Contacts_RcontactsTestCase
class without creating the PaginationHelper
class object in D_TC_Contacts_RcontactsTestCase
class ?
Aucun commentaire:
Enregistrer un commentaire