Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8136295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:42:56+00:00 2026-06-06T10:42:56+00:00

I’m using Selenium WebDriver with Testng (started using an .xml file) to test a

  • 0

I’m using Selenium WebDriver with Testng (started using an .xml file) to test a site using multiple browsers.

I’m trying to create a method which will take in a parameter from the xml file, and using an IF statement, detect the browser, create the relevant driver, and return it.

The trouble I’m having is when I try to pass through the parameter to the method. If I pass through “Chrome” for example, the IF statement works fine and the driver is created. However if I use the parameter itself, the driver isn’t created and the test fails the first time it is used.

Here’s the set up code I’m using:

@Parameters ({"driver_property_value","driver_property_location","browser"})
@BeforeClass
public void setUp(String driverPropertyValue, String driverPropertyLocation, String browser) throws Exception {
    Setup setup = new Setup();

    //set properties
    System.setProperty(setup.driverPropertyValue(driverPropertyValue),setup.driverPropertyLocation(driverPropertyLocation));
    driver = setup.driver(browser);
    baseUrl = setup.baseURL();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

here’s what it’s calling:

public WebDriver driver(String browser)
{
    WebDriver value = null;

    if (browser == "chrome")
    {
    value = new ChromeDriver();
    }
    return value;
}

and here’s the testng xml that I’m using to run the tests and pass the parameters in:

<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd">
<suite name = "testng" verbose="1">
<parameter name="driver_property_value" value="webdriver.chrome.driver"/>
<parameter name="driver_property_location" value="C:/chromedriver.exe"/>
<parameter name="browser" value="chrome"/>
<test name="chrome_tests">
    <packages>
        <package name="com.LoginPage"/>
    </packages>
</test>

The first setup seems to be working fine, it’s just the the driver selection that doesn’t seem to work when using a parameter.

Any help or advice would be appreciated.

Thanks

p.s. here’s a failure trace, not sure if it’ll help or not.

java.lang.NullPointerException
at com.LoginPage.Login_Logout.setUp(Login_Logout.java:33)
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)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:543)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:212)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:753)
at org.testng.TestRunner.run(TestRunner.java:613)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1137)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1062)
at org.testng.TestNG.run(TestNG.java:974)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T10:42:57+00:00Added an answer on June 6, 2026 at 10:42 am

    Do not use the reference equality operator == to compare Strings. Use equals or equalsIgnoreCase.

    The reference equality operator checks that both operands refer to the same instance of an object. With Strings and many object types, this will rarely work the way you expect.

    The expression browser == "chrome" resolves to false because even if the browser variable has the value "chrome", it will most likely be a different instance of the string representing "chrome". For much more detail on what this means, please refer to this question.

    So with that expression resolving to false, driver returns a null, which your setUp proceeds to use happily as though it’s a valid object instance, resulting in the NullPointerException.

    Change your comparison to this:

    if (browser.equals("chrome")) {
       value = new ChromeDriver();
    }
    

    There are several variations to this statement. You can use equalsIgnoreCase to match "chrome" in any combination of character cases, and you could reverse the order of the literal "chrome" and the browser local variable. What this would do is prevent a NullPointerException from occurring on that line if null was passed in as the browser parameter.

    if ("chrome".equalsIgnoreCase(browser)) {
       value = new ChromeDriver();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.