1

I created constructor for my class in selenium, when i am trying to execute my script its not running and showing below message

Error Message:

  Default test     
Tests run: 0, Failures: 0, Skips: 0 
Default suite 
Total tests run: 0, Failures: 0, Skips: 0 
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@73846619: 1 ms [TestNG] Time taken by org.testng.reporters.XMLReporter@49993335: 6 ms [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@dc24521: 17 ms [TestNG] Time taken by org.testng.reporters.EmailableReporter2@2038ae61: 5 ms [TestNG] Time taken by org.testng.reporters.jq.Main@6e0e048a: 43 ms

Code:

public class HomePageActions {      
  static WebDriver driver;      
  public HomePageActions(WebDriver driver){         
  this.driver=driver;   
  }         
  @BeforeClass  

enter code here
    public void startup(){      
    System.setProperty("webdriver.gecko.driver",
    "D:/krishna//geckodriver-v0.11.1-win32//geckodriver.exe");
    System.setProperty("webdriver.chrome.driver", "D://krishna//chromedriver_win32//chromedriver.exe"); 
    driver = new ChromeDriver();        
    //driver=new FirefoxDriver();       driver.navigate().to("http://***********/");        driver.manage().window().maximize();            
    }       
    @Test   
    public void CheckImportantNoticeSection(){      
      HomePage home = new HomePage(driver);
      LoginPage login = new LoginPage(driver);
      login.AgentLogin("+++++", "*********@gmail.com", "***"); 
      System.out.println(driver.getTitle());        
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);       
      home.check_ImportantNoticeSectionAvailableOrNot();    
    }
Krishna
  • 21
  • 1
  • 6

1 Answers1

0

Remove the constructor, it should work fine. First of all, use constructor to initialize only instance variables. You have made the Webdriver driver as static and if you really want to change the default values of static variables then use a Static Block. You need a no arg constructor, else testNG will throw an error.

Please understand how testNG works in the back end.

How does all annotations work in TestNg without main() method

Community
  • 1
  • 1
shank087
  • 492
  • 8
  • 17
  • Hi shank,Here i need constructor why because i am calling methods of this class in another class.Have you any idea about how to call these methods without creating constructor,without creating constructor it showing exception as: java.lang.NullPointerException – Krishna Jan 30 '17 at 12:19
  • You can use groups and depends on groups tags. Refer this link on how to use it http://stackoverflow.com/questions/7692129/testng-dependsonmethods-from-different-class – shank087 Jan 30 '17 at 12:26