java.lang.NullPointerException:Cannot invoke”org.openqa.selenium.SearchContext.findElement(org.openqa.selenium.By)”because”this.searchContext” is null

I created 3 file, one is common which is hold common opening browser detail and dashboard page object. And second one is for homepage testcase and third one is for loginIn page or after login page element find test case.

I am able to run dashbaord test case.but i want also run testcase for LogedIn, i can’t.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package BaseDataSource;
import java.io.FileInputStream;
import java.io.IOException;
import java.time.Duration;
import java.util.Properties;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import ParaBank.AutomationTestCase.DashBoard;
import io.github.bonigarcia.wdm.WebDriverManager;
public class MainDataSourceTest
{
public WebDriver driver;
public DashBoard dashboard;
public WebDriver inisilaizebroswer() throws IOException {
Properties prop = new Properties();
FileInputStream file = new FileInputStream(System.getProperty("user.dir")+"\src\main\java\SourceData\DataSource.properties");
prop.load(file);
String browserName=prop.getProperty("browser");
if(browserName.equalsIgnoreCase("chrome"))
{
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
}
else if(browserName.equalsIgnoreCase("firefox")) {
}
else if(browserName.equalsIgnoreCase("chrome")) {
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
return driver;
}
@BeforeTest
public DashBoard LuanchApp() throws IOException
{
driver = inisilaizebroswer();
dashboard = new DashBoard(driver);
dashboard.GotoURL();
return dashboard;
}
public void closedriver()
{
driver.close();
}
}
</code>
<code>package BaseDataSource; import java.io.FileInputStream; import java.io.IOException; import java.time.Duration; import java.util.Properties; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import ParaBank.AutomationTestCase.DashBoard; import io.github.bonigarcia.wdm.WebDriverManager; public class MainDataSourceTest { public WebDriver driver; public DashBoard dashboard; public WebDriver inisilaizebroswer() throws IOException { Properties prop = new Properties(); FileInputStream file = new FileInputStream(System.getProperty("user.dir")+"\src\main\java\SourceData\DataSource.properties"); prop.load(file); String browserName=prop.getProperty("browser"); if(browserName.equalsIgnoreCase("chrome")) { WebDriverManager.chromedriver().setup(); driver = new ChromeDriver(); } else if(browserName.equalsIgnoreCase("firefox")) { } else if(browserName.equalsIgnoreCase("chrome")) { } driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); return driver; } @BeforeTest public DashBoard LuanchApp() throws IOException { driver = inisilaizebroswer(); dashboard = new DashBoard(driver); dashboard.GotoURL(); return dashboard; } public void closedriver() { driver.close(); } } </code>
package BaseDataSource;

import java.io.FileInputStream;
import java.io.IOException;
import java.time.Duration;
import java.util.Properties;
 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;

import ParaBank.AutomationTestCase.DashBoard;
import io.github.bonigarcia.wdm.WebDriverManager;

public class MainDataSourceTest 
{

    public WebDriver driver;
    public DashBoard dashboard;
    
    public WebDriver inisilaizebroswer() throws IOException {
        
        Properties prop = new Properties();
        FileInputStream file = new FileInputStream(System.getProperty("user.dir")+"\src\main\java\SourceData\DataSource.properties");
        prop.load(file);
        
         String browserName=prop.getProperty("browser");
         
         if(browserName.equalsIgnoreCase("chrome")) 
         { 
             WebDriverManager.chromedriver().setup();
             driver = new ChromeDriver();
         }
         else if(browserName.equalsIgnoreCase("firefox")) {
             
         }
         else if(browserName.equalsIgnoreCase("chrome")) {
             
         }
         
         driver.manage().window().maximize();
         driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
         return driver;
         
        
    }
    
    @BeforeTest
    public DashBoard LuanchApp() throws IOException
    {
        driver = inisilaizebroswer();
        dashboard = new DashBoard(driver);
        dashboard.GotoURL();
        return dashboard;
        
        
    }
    
    
    public void closedriver()
    {
        driver.close();
        
        
    }
    
    
    
}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package ParaBank.AutomationTestCase;
import org.testng.Assert;
import org.testng.annotations.Test;
import BaseDataSource.MainDataSourceTest;
public class LogedInTest extends MainDataSourceTest
{
LogedIn acc = new LogedIn(driver);
@Test
public void login()
{
dashboard.clicksubmit("BhaveshSolanki", "Bhavesh@1234");
}
@Test
public void accounttest(){
acc.newAccout();
}
}
</code>
<code>package ParaBank.AutomationTestCase; import org.testng.Assert; import org.testng.annotations.Test; import BaseDataSource.MainDataSourceTest; public class LogedInTest extends MainDataSourceTest { LogedIn acc = new LogedIn(driver); @Test public void login() { dashboard.clicksubmit("BhaveshSolanki", "Bhavesh@1234"); } @Test public void accounttest(){ acc.newAccout(); } } </code>
package ParaBank.AutomationTestCase;

import org.testng.Assert;
import org.testng.annotations.Test;
import BaseDataSource.MainDataSourceTest;

public class LogedInTest extends MainDataSourceTest

{
    
    
    LogedIn acc = new LogedIn(driver);
    @Test
    public void login() 
    {
            dashboard.clicksubmit("BhaveshSolanki", "Bhavesh@1234");
    }
    @Test
    public void accounttest(){
        
            acc.newAccout();
    }

}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package ParaBank.AutomationTestCase;
import org.testng.Assert;
import org.testng.annotations.Test;
import BaseDataSource.MainDataSourceTest;
public class DashBoardTest extends MainDataSourceTest
{
@Test
public void login()
{
dashboard.clicksubmit("BhaveshSolanki", "Bhavesh@1234");
}
@Test
public void about()
{
String about = dashboard.VerifyAboutus();
Assert.assertEquals(about, "https://parabank.parasoft.com/parabank/about.htm");
}
@Test
public void service() {
String Service = dashboard.VerifyServices();
Assert.assertEquals(Service, "https://parabank.parasoft.com/parabank/services.htm");
}
@Test
public void products() {
String Products = dashboard.VerifyProducts();
Assert.assertEquals(Products, "http://www.parasoft.com/jsp/products.jsp");
}
@Test
public void location() {
String Location = dashboard.VerifyLocations();
Assert.assertEquals(Location,
"http://www.parasoft.com/jsp/pr/contacts.jsp");
}
@Test
public void adminpage() {
String admin = dashboard.VerifyAdminPage();
Assert.assertEquals(admin,
"https://parabank.parasoft.com/parabank/admin.htm");
}
@Test
public void RegisterURL()
{
dashboard.clickRegister();
}
}
</code>
<code>package ParaBank.AutomationTestCase; import org.testng.Assert; import org.testng.annotations.Test; import BaseDataSource.MainDataSourceTest; public class DashBoardTest extends MainDataSourceTest { @Test public void login() { dashboard.clicksubmit("BhaveshSolanki", "Bhavesh@1234"); } @Test public void about() { String about = dashboard.VerifyAboutus(); Assert.assertEquals(about, "https://parabank.parasoft.com/parabank/about.htm"); } @Test public void service() { String Service = dashboard.VerifyServices(); Assert.assertEquals(Service, "https://parabank.parasoft.com/parabank/services.htm"); } @Test public void products() { String Products = dashboard.VerifyProducts(); Assert.assertEquals(Products, "http://www.parasoft.com/jsp/products.jsp"); } @Test public void location() { String Location = dashboard.VerifyLocations(); Assert.assertEquals(Location, "http://www.parasoft.com/jsp/pr/contacts.jsp"); } @Test public void adminpage() { String admin = dashboard.VerifyAdminPage(); Assert.assertEquals(admin, "https://parabank.parasoft.com/parabank/admin.htm"); } @Test public void RegisterURL() { dashboard.clickRegister(); } } </code>
package ParaBank.AutomationTestCase;

import org.testng.Assert;
import org.testng.annotations.Test;
import BaseDataSource.MainDataSourceTest;

public class DashBoardTest extends MainDataSourceTest

{
    @Test
    public void login() 
    {
            dashboard.clicksubmit("BhaveshSolanki", "Bhavesh@1234");
    }
    @Test
    public void about()
    {
        String about = dashboard.VerifyAboutus();
        Assert.assertEquals(about, "https://parabank.parasoft.com/parabank/about.htm");
    }   
    @Test
    public void service() {
        
        String Service = dashboard.VerifyServices();
        Assert.assertEquals(Service, "https://parabank.parasoft.com/parabank/services.htm");
    }
    
    @Test
    public void products() {
         String Products = dashboard.VerifyProducts();
         Assert.assertEquals(Products, "http://www.parasoft.com/jsp/products.jsp");
    }
    
    @Test
    public void location() {
         String Location = dashboard.VerifyLocations(); 
         Assert.assertEquals(Location,
          "http://www.parasoft.com/jsp/pr/contacts.jsp");
    }
    
    @Test
    public void adminpage() {
        String admin = dashboard.VerifyAdminPage();
        Assert.assertEquals(admin, 
                "https://parabank.parasoft.com/parabank/admin.htm");
            
    }
    @Test
    public void RegisterURL() 
    {
            dashboard.clickRegister();
    }

}

I am able suceesfully run dashboard.class testcasts but i am not able to LogedIn.class test cases.

can you please help me to resolve null exception.

New contributor

Bhavesh Solanki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật