//This is Base Class
package base;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class BaseClass
{
WebDriver driver;
public void setup()
{
System.setProperty("WebDriver.chrome.driver", "C:/Users/MY PC/Desktop/Kunal/Selenium/chromedriver.exe");
driver = new ChromeDriver();
driver.get("URL");
driver.manage().window().maximize();
}
}
//This is Login Class
package pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class Login
{
WebDriver driver;
By EmailID = By.name("username");
By Pass = By.id("mat-input-1");
public Login(WebDriver driver)
{
this.driver = driver;
}
public void login(String Email, String Password)
{
driver.findElement(EmailID).sendKeys(Email);
driver.findElement(Pass).sendKeys(Password);
driver.findElement(By.xpath("/html/body/app-root/app-login-user/div/div/mat-card/div/div[2]/form/div[3]/button/span")).click();
}
}
//This is Test which I want to run and I am getting 'Null Pointer Exception' as soon as I clicked on 'Run' button of Eclipse
NOTE: I have mentioned valid "EmailID" and "Password" while passing the parameters.
package test;
import org.openqa.selenium.WebDriver;
import base.BaseClass;
import pages.Login;
public class LoginTest extends BaseClass
{
static WebDriver driver;
public static void main(String[] args)
{
try
{
Login log = new Login(driver);
log.login("EmailID", "Password");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
请让我知道我到底在哪里陷入困境...
提前致谢。
问候, 库纳尔