0

I'm new to selenium framework, i am trying to create a framework and started my steps towards learning framework. I have written a code for login page but here i'm getting "nullPointerException". Anyone's help would be better. Thanks in advance. enter image description hereenter image description here

5
  • Use Inheritance concept inside login page class. Because you have set up your browsers in another class file, so you have to class that file from login page. Commented Mar 17, 2017 at 5:08
  • can you suggest me, what i have to do in login page class. What changes make in login page will be useful ? Commented Mar 17, 2017 at 5:16
  • you are not calling the startBrowser method at all. Commented Mar 17, 2017 at 5:17
  • public class LoginPage extends Utility Before Going with selenium first you should learn basic core concepts, then only you will be able to create effective test automation script. Take this comment as an advice :) it will help you. Commented Mar 17, 2017 at 5:37
  • Yes Sure, Thank you. Commented Mar 17, 2017 at 6:12

4 Answers 4

1

Your driver is not initialised ,for which the code you have written in Utility Class, you can extend UtlitlityClass in your LoginPage and use @BeforeMefthod in LoginPage where you can create an instance of driver and use it in your test method and @AfterMethod to destroy the same.

Sign up to request clarification or add additional context in comments.

2 Comments

I have updated my code like this.still getting the same exception.
which browser you are tying to open ?
0

This is because of Declaring the WebDriver driver; in both parent class and child class.

Example : 1.created one base class and in base class declaring the Webdrievr; 2.Created child class and declare the webdriver in child class. 3.child class extends base class. this issue comes.

So declare the WebDriver driver in either Base class or Child Class.

Comments

0

Better place the editable code so that it can get rectified; 1. Remove static from static webdriver driver in Utility 2. Remove webdriver declared in Login page

Question: Does base url launches homepag or signin page If home page then 1. Create a home page class 2. In utility- make this asignment --
Homepage homepgobj = driver.get(url) ;
return homepgobj;
and replace void with text Homepage. 3. Now in Homepage Create method to navigate to Login page using pagefactory In
public LogInPage navigateToLoginPage(){
driver.navigate().to("Loginpage url");
LoginPage logInPageObj = PageFactory.initElements(driver, LoginPage.class);
return loginPageObj; } 4. On homepage create const. to driverobj just like done in login page but do not place pagefactory in it 5. Also remove page factory element from const. of Signin page 6. Create login page test class to write tests . Now while writin test navigate to signin page like this Homepage homepgObj = startBrowser(browser, url) --
--this will navigate to homepage
Login loginpgObj = homepgObj.callmethodcreatedinhomepage] --
-- will navigate to signin page.

 loginpgObj.[Call methods of loginpg]

Comments

0

I was also facing the same problem. As I am using BaseClass (parent class) for my tests where I declared WebDrive driver and mistakenly I also declared Webdriver in my test class (child class). It was making a duplicated declaration of the driver. Just removing, WebDriver driver; from child class, this issue resolved

Comments

Your Answer

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.