I am getting compilation error when I am extending Loginpage class through Loginbusiness, define a method but compilation throws an error to remove illegal identifiers(eg. public) and also for arguments passed to that methods:
Login Page:
package com.pages.page;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import com.utility.PageUtility;
public class LoginPage {
public LoginPage(WebDriver driver) {
PageFactory.initElements(driver, this);
}
@FindBy(how = How.ID, using = PageUtility.SIGNIN_USERNAME_ID)
@CacheLookup
public WebElement userNameTextField;
@FindBy(how = How.ID, using = PageUtility.SIGNIN_PASSWORD_ID)
@CacheLookup
public WebElement passwordTextField;
@FindBy(how = How.ID, using = PageUtility.SIGNIN_SUBMIT_ID)
@CacheLookup
public WebElement signInButton;
}
LoginBusiness:
package com.business;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;
import com.driver.Driver;
import com.page.LoginPage;
public class LoginBusiness extends LoginPage {
public LoginPage loginpage;
public LoginBusiness(WebDriver driver) {
super(driver);
// TODO Auto-generated constructor stub
// loginpage = PageFactory.initElements(Driver.getDriver(), LoginPage.class);
WebElement loginToApplication(String username String password) {
userNameTextField.clear();
userNameTextField.sendKeys("aaaa");
passwordTextField.clear();
passwordTextField.sendKeys("4444");
signInButton.click();
}
}}
1 Answer 1
Ok so there is a couple of things wrong in there:
- Do you really need
LoginBusiness
class? Seems like it all could be done inLoginPage
. - If you don't use the
WebElements
anywhere outside theLoginBusiness
class they can beprotected
instead ofpublic
. - remove the line with
public LoginPage loginpage;
, you already extended the class, this is probably causing the compilation issue. - Inside
LoginBusiness
class define a private variableprivate WebDriver driver;
and set it inside the constructorthis.driver = driver;
- Your
loginToApplication
function is of typeWebElement
while it does not return anyWebElements
. Instead make itpublic void
and don't return anything. Or make it return the page that you land on after login (and its type not void).
Half of those errors were probably pointed out to you by the compiler...
Adding the refactored LoginBusiness
class here:
public class LoginBusiness extends LoginPage {
public LoginBusiness(WebDriver driver) {
super(driver);
}
// loginpage = PageFactory.initElements(Driver.getDriver(), LoginPage.class);
public void loginToApplication(String username, String password) {
userNameTextField.clear();
userNameTextField.sendKeys("aaaa");
passwordTextField.clear();
passwordTextField.sendKeys("4444");
signInButton.click();
}
}
-
As per the architecture we have to define methods of every page in the loginbusiness class, and I have return public void but it throws compilation errorjay– jay2019年05月09日 19:36:53 +00:00Commented May 9, 2019 at 19:36
-
Post the log please, code alone is not enough.Moro– Moro2019年05月09日 19:38:20 +00:00Commented May 9, 2019 at 19:38
-
Multiple markers at this line - Syntax error on token ")", ; expected - Syntax error on token "(", ; expected-- showing this kind of messagesjay– jay2019年05月09日 19:55:23 +00:00Commented May 9, 2019 at 19:55
-
I have edited my answer with the fixed
LoginBusiness
class, this should help you proceed.Moro– Moro2019年05月09日 20:15:29 +00:00Commented May 9, 2019 at 20:15 -
If I helped you solve the problem please remember to tick the answer.Moro– Moro2019年05月09日 20:49:56 +00:00Commented May 9, 2019 at 20:49
Explore related questions
See similar questions with these tags.