我修好了。我擴展了方法所在的AbstractPage
。起初我會得到一個Test類必須有一個單獨的無參數構造函數。然後我意識到在@Before之後,驅動程序變量和啓動變量在刪除這些內容後出現問題,只是將其稱爲開放式chromedriver()
方法和openhomepage
方法,eclipse非常高興,它允許我運行測試並刪除必須的部分調用類然後調用方法。謝謝您的幫助。有沒有不同的方法來使用另一個類的方法?
package seleniumTests.QA.com;
public class Testforpage {
private WebDriver driver;
@Before
public void SetUp() {
AbstractPage startUp = new AbstractPage(driver);
driver = startUp.openChromeDriver();
onRegistrationPage = new RegistrationPage(driver);
onRegistrationPage.openHomePage(driver);
}
@Test
public void register() {
onRegistrationPage.clickOn(onRegistrationPage.REGISTRATION_LINK);
assertEquals(onRegistrationPage.getURL(),"http://demoqa.com/registration/");
// Write first name**
onRegistrationPage.type(onRegistrationPage.FIRST_NAME_INPUT, "User");
// Write last name
onRegistrationPage.type(onRegistrationPage.LAST_NAME_INPUT, "Dev");
// click marrital status
onRegistrationPage.clickOn(onRegistrationPage.MARITAL_STATUS_BUTTON);
// click hobby
onRegistrationPage.clickOn(onRegistrationPage.HOBBY_BUTTON);
這就是代碼現在的樣子。
public class Testforpage extends AbstractPage {
public Testforpage() {
}
@Before
public void SetUp() {
driver = openChromeDriver();
openHomePage(driver);
}
@Test
public void register() {
clickOn(REGISTRATION_LINK);
assertEquals(getURL(),"http://demoqa.com/registration/");
// Write first name**
type(FIRST_NAME_INPUT, "User");
// Write last name
type(LAST_NAME_INPUT, "Dev");
// click marrital status
clickOn(MARITAL_STATUS_BUTTON);
我會建議,至少,原始(或最新版本)發佈爲「保留」版本。在沒有問題的情況下,我們有兩個答案現在沒有意義。 –
是否有理由不能刪除自己的問題?我不認爲有刪除自己的問題/答案/評論的聲譽要求。 –
重新打開請求。我花了一些時間考慮這個問題,並藉助我的一個答案來解決問題。我還爲我的問題發佈瞭解決方案。 – Kenandrae