question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parameter with BeforeTest is not reading more than one class test

See original GitHub issue

Hello All,

I have two test case classes, Test1.java

                 @Test
             public void runTestCase(){
            System.out.println("Test is running 1 "); 
                  }

Test2.java

          @Test
       public void runTestCase(){
      System.out.println("Test is running 2 ");
      }

I have one base class where the parameters are defined with @BeforeTest(). BaseClass.java

import org.testng.annotations.AfterClass;`
   import org.testng.annotations.BeforeClass;
   import org.testng.annotations.BeforeTest;
   import org.testng.annotations.Parameters;

 public class BasicClass  {
  private String browserName;
        @Parameters({"Browser"})
    @BeforeTest()
    public void getBrowserNameFromTestNG(String browserName){   
        this.browserName = browserName;
    }


    @BeforeClass
    public void setUp(){

        String browser = browserName;

        if(browser.equals("Chrome")){
            System.out.println("Chrome Launched Successfully");
        }else if(browser.equals("Firefox")){
            System.out.println("Firefox Launched Successfully");
        }else{
            System.out.println("IE Launched Successfully");
        }

    }

    @AfterClass
    public void tearDown(){
        System.out.println("Closing Browser");
    }

testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Testing Parameterization" parallel="false" thread-count="3">
<test  verbose="1" name="Test_Chrome">
     <parameter name="Browser" value="Chrome"/>
     <classes>
            <class name="Test1.java" />
            <class name="Test2.java" />
    </classes>
 </test>

<test  verbose="1" name="Test_Firefox"> 
     <parameter name="Browser" value="Chrome"/>
     <classes>
            <class name="Test1.java" />
            <class name="Test2.java" />
    </classes>
 </test>

</suite>

Objective: Need to run two test cases (which is available in one package) with different browsers. Base class will call browser one time and set it for running accordingly.

Issue: When i run testng.xml, it is taking only the first class Test1.java and for Test2.java is showing configuration issue as Null Point Exception.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
NisVek-Automationcommented, Jul 8, 2021

@Vishnu1067 I am having the same issue using the same structure as you used. Please let me know if you get any workaround for the same.

0reactions
freedombycryptocommented, Feb 11, 2016

Hi,

Thanks for sharing the link and it is not my scenario. I want parameterization

my scenario would be like this,

Lets say Application model;

Module A - 5 screens (Quote, Booking, File, etc) Module B - 3 Pages

Eclipse structure

Creating Test Packages Package 1 - modulea - 5 class - each class have minimum 20 test cases Package 2 - moduleb - 3 class - each class have minimum 20 test cases

<test package 1 with firefox> <parameter> <class1> <class2> <class3> <class4> <class5> </test>

<test package 1 with IE> <parameter> <class1> <class2> <class3> <class4> <class5> </test>

<test package 2 with firefox> <parameter> <class1> <class2> <class3> </test>

<test package 2 with IE> <parameter> <class1> <class2> <class3> </test>

now i want to execute all the cases in chrome, Firefox and IE in parallel. All test cases in one class should execute in same browser (not launch browser on each test case).

This is my scenario. Anyway i’ve made work around my framework until new feature comes up.

Once again thanks for reply.

Regards, Vishnu.

Read more comments on GitHub >

github_iconTop Results From Across the Web

parameter is required by @ Test but has not been marked ...
You are getting this error as you are directly running this class. You should run your TestNG XML file.
Read more >
org.testng.TestNGException: Parameter 'browser' is required ...
My requirement is that I need to run multiple test classes in parallel but want to call @BeforeSuite in only 1st test class...
Read more >
Documentation - TestNG
A TestNG class is a Java class that contains at least one TestNG annotation. It is represented by the <class> tag and can...
Read more >
Annotations - TestNG Docs
Here is a quick overview of the annotations available in TestNG along with ... to centralize test setup for multiple test classes in...
Read more >
TestNG
The factory method can receive parameters just like @Test and @Before/After and it must return Object[]. The objects returned can be of any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found