1

enter image description hereI have a Simple Selenium code and i am Trying to run it on Remote Browser(Browser Stack).Trying to Open a Browser and Logging in to the application. So my code is running and i am able to open the browser but unable to log in. What am i doing wrong. This is the Error message displayed

here https://www.hzelectric.com/

PASSED: URLCHECK

FAILED: ARegistrationandLogout

java.lang.NullPointerException at com.testngsample.SampleTest.ARegistrationandLogout(SampleTest.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source)

1

2 Answers 2

1

It seems that the test script has not initialised the WebDriver object in the ARegistrationandLogout test method. I suggest adding the capabilities and initialise the WebDriver instance again in the ARegistrationandLogout test method.

Use Capabilities

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

Comments

0

You are initialising the WebDriver instance in method - 'URLCHECK' and using the same instance in method - 'ARegistrationandLogout' (which is not initialised, hence NullPointerException is printed)

Since you are using TestNG, you need to do something like this..

public class UnitTestClass {

public WebDriver webDriver = null;
public DesiredCapabilities caps = null;

@BeforeTest
public void beforeTest() {
    try {
        caps = new DesiredCapabilities();
        caps.setCapability("os", "Windows");
        caps.setCapability("os_version", "8.1");
        caps.setCapability("browser", "Firefox");
        caps.setCapability("browser_version", "63.0 beta");

        webDriver = new RemoteWebDriver(new URL("http://<USERNAME>:<ACCESS_KEY>@hub-cloud.browserstack.com/wd/hub"), caps);
    } catch (Exception e) {
        e.printStackTrace();
    }
} // BEFORE TEST END

@Test
public void UnitTest() {
    webDriver.get("https://www.google.com/");
} // TEST END

@AfterClass
public void afterClass() {
    if(webDriver != null){
        webDriver.quit();
    }
} // AFTER TEST END }

I would recommend you to review these online resources - #guru99, #ToolsQA, #TestNG_Docs

I see you are trying to test on BrowserStack. They have a detailed documentation around the same. You can view the TestNG-BrowserStack doc here. They have a sample GIT repository as well - #TestNG-BrowserStack-GIT-Repo

1 Comment

Thanks Worked like a Charm. I initialised the webdriver again and worked for me

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.