2015-08-15 57 views
0

我已經在我的測試腳本下面的代碼在Selenium測試腳本中有多個同一頁面的對象可以嗎?

@Test 

public void homePageNavigation() 

{ 
    LoginPage loginPage = PageFactory.initElements(driver, LoginPage.class); 

    //login function returns the HomePage object 
    HomePage homePage = loginPage.login(login, pass); 

    //navgateToProfilePage() function returns a ProfilePage object 
    ProfilePage profilePage = homePage.navgateToProfilePage(); 

    //navigateBackToHomePage() function returns HomePage object and 
    //takes the user back to Home Page again 
    HomePage homePageReturn=profilePage.navigateBackToHomePage(); 

} 

現在在上面的代碼,我有HomePagehomePagehomePageReturn 2個對象。在腳本中進一步使用它們可以嗎?

感謝 拉詹

+0

爲什麼你不能navigateBackToHomePage();返回相同的對象,如「返回此;」 –

+0

navigateBackToHomePage()函數在ProfilePage類中。 如果我寫回來這個,該函數將返回當前對象,即ProfilePage對象。 – Rajan

回答

0

爲什麼不把自然界中的Page對象靜態的,所以,你可以調用任何方法,無需進行多次的init()

你做

首頁首頁 首頁homePageReturn

如果主頁是靜態的,你可以直接調用該方法。但不知道你是如何實現你的代碼的。

相關問題