0

I'm trying to implement the concept of Page Object using TestNG. I created a BrowserFactory class that has the information to initialize the browser. I also created a class called LogSystemPage that has the information of the screen elements that I need to interact with.

Lastly, I created a test class called ValidateStatusTestNG that "calls" the BrowserFactory and LogSystemPage classes.

When I try to run the test method called logarSystem, the Eclipse console displays the following error message: java.lang.NullPointerException. Following is the code, the error message and the images.

public class BrowserFactory {

static WebDriver driver;

public static WebDriver startBrowser(String url) {

    System.setProperty("webdriver.chrome.driver", "E:\\Selenium\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.get(url);


    return driver;
}}

public class LogarSistemaPage {

private static WebDriver driver;

public WebDriver logarSistema(WebDriver driver) {

    driver.findElement(By.id("matricula_I")).sendKeys("844502");
    driver.findElement(By.id("senha_I")).sendKeys("Pw34Jdt#*");
    driver.findElement(By.id("bt_entrar")).click();

    return driver;

}}

public class ValidarStatusTestNG {

static WebDriver driver;

@BeforeClass
public void setUp() throws Exception {

    BrowserFactory b = new BrowserFactory();
    b.startBrowser("http://10.5.9.45/BKOMais_S86825EstrategiaBackOfficeClaroFixo/");

}

@Test
public void logarSistema(){

    LogarSistemaPage s = new LogarSistemaPage();
    s.logarSistema(driver);

}

@AfterClass
public static void closeBrowser() {

    //driver.quit();

}}

TestNGErro_1

TestNGErro_2

TestNGErro_3

JeffC
  • 22,180
  • 5
  • 32
  • 55
Kakashi - Sensei
  • 371
  • 1
  • 6
  • 22

1 Answers1

0

driver =b.startBrowser("http://10.5.9.45/BKOMais_S86825EstrategiaBackOfficeClaroFixo/") You need to assign the return value of method returning driver to driver.

    @BeforeClass
public void setUp() throws Exception {

    BrowserFactory b = new BrowserFactory();
driver =b.startBrowser("http://10.5.9.45/BKOMais_S86825EstrategiaBackOfficeClaroFixo/");

}

@Test
public void logarSistema(){

    LogarSistemaPage s = new LogarSistemaPage();
    s.logarSistema(driver);

}

That should do the work.

PJAutomator
  • 344
  • 3
  • 12