0

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();
 }
 }}
asked May 9, 2019 at 14:17

1 Answer 1

0

Ok so there is a couple of things wrong in there:

  1. Do you really need LoginBusiness class? Seems like it all could be done in LoginPage.
  2. If you don't use the WebElements anywhere outside the LoginBusiness class they can be protected instead of public.
  3. remove the line with public LoginPage loginpage;, you already extended the class, this is probably causing the compilation issue.
  4. Inside LoginBusiness class define a private variable private WebDriver driver; and set it inside the constructor this.driver = driver;
  5. Your loginToApplication function is of type WebElement while it does not return any WebElements. Instead make it public 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();
}

}

answered May 9, 2019 at 15:44
6
  • 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 error Commented May 9, 2019 at 19:36
  • Post the log please, code alone is not enough. Commented 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 messages Commented May 9, 2019 at 19:55
  • I have edited my answer with the fixed LoginBusiness class, this should help you proceed. Commented May 9, 2019 at 20:15
  • If I helped you solve the problem please remember to tick the answer. Commented May 9, 2019 at 20:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.