I'm trying to run TestNG with Selenium in Eclipse.
When the Class file is Run As a TestNG Test, I'm getting the Tests Run = 0.
What could the issue be?
I have the testNg plugin & jar files configured.
testng.xml file:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="WikiTestSuite" verbose="3" parallel="methods">
<test name="WikiTestCase">
<classes>
<class name="com.selenium.WebDriverTest" />
</classes>
</test>
</suite>
Classes:
WebDriverTest class:
package com.selenium;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
public class WebDriverTest extends BrowserInstance{
private void WebDrive() {
// navigate to specified browser
wDriver.get("http://www.wikipedia.com");
// assert wikipedia is opened
Assert.assertEquals(wDriver.getTitle(), "http://www.wikipedia.com");
System.out.println("Page title is correct. PASS!");
}
}
BrowserInstance class:
package com.selenium;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
public class BrowserInstance {
// initialize webdriver object reference
WebDriver wDriver;
@BeforeMethod
public void launchBrowser() {
wDriver = new FirefoxDriver();
System.out.println("In launchBrowser method");
}
@AfterMethod
public void closeBrowser() {
wDriver.close();
wDriver.quit();
System.out.println("In closeBrowser method");
}
}
Note:
When I run the testing.xml file as a TestNG Suite, the results are:
[TestRunner] Running the tests in 'WikiTestCase' with parallel mode:methods
[RunInfo] Adding method selector: org.testng.internal.XmlMethodSelector@7426dbec priority: 10
[TestClass] Creating TestClass for [ClassImpl class=com.selenium.WebDriverTest]
[TestNG] Running:
/Users/developer/Documents/workspace/SeleniumTest1/lib/testng.xml
[SuiteRunner] Created 1 TestRunners
[TestRunner] Running test WikiTestCase on 1 classes, included groups:[] excluded groups:[]
===== Test class
com.selenium.WebDriverTest
@BeforeMethod BrowserInstance.launchBrowser()[pri:0, instance:com.selenium.WebDriverTest@4979935d]
@AfterMethod BrowserInstance.closeBrowser()[pri:0, instance:com.selenium.WebDriverTest@4979935d]
======
===== Invoked methods
=====
Creating /Users/developer/Documents/workspace/SeleniumTest1/test-output/WikiTestSuite/WikiTestCase.html
Creating /Users/developer/Documents/workspace/SeleniumTest1/test-output/WikiTestSuite/WikiTestCase.xml
===============================================
WikiTestCase
Tests run: 0, Failures: 0, Skips: 0
===============================================
===============================================
WikiTestSuite
Total tests run: 0, Failures: 0, Skips: 0
===============================================
When I run the .java file as a TestNG Test, the results are:
[TestNG] Running:
/private/var/folders/q6/xqd3z8fx69z05pbclbx_bj740000gp/T/testng-eclipse--953413131/testng-customsuite.xml
===============================================
Default test
Tests run: 0, Failures: 0, Skips: 0
===============================================
===============================================
Suite
Total tests run: 0, Failures: 0, Skips: 0
===============================================
In both cases, the result is "Tests Run = 0".
Any help will be much appreciated.
Thanks!
EDIT: I found the solution: I used a 'private' method in my .java file.
I was able to rectify the bug but I'm now wondering why TestNG does not run a private method.
Any input is welcome.
Thanks!