Reputation: 528
I am trying to run test cases using JUNIT 4.10 with Selenium for a Web Application using Maven in Eclipse.
I have created a simple java project with JUNIT Test cases added proper dependency.
It works perfectly fine with Run as a JUNIT Test case
but it does not work as Maven Test so something like mvn clean test
is not working.
Here is my excerpt of pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
</plugin>
</plugins>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.25.0</version>
<type>jar</type>
<scope>test</scope>
</dependency>
also here is my JUnit Test case which I wrote,
@Test()
public void testTC101() throws InterruptedException{
driver.get(ADMIN_BASE_URL_QA);
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='top30Events']"));
WebElement loanModFullEvent = driver.findElement(By.partialLinkText(QA_MOD_FULL_EVENT));
loanModFullEvent.click();
String clickedFullEventId = loanModFullEvent.findElement(By.xpath("..")).getAttribute("id").split("_")[1];
List<WebElement> nearbyEvents = driver.findElements(By.id("nearby_events_" + clickedFullEventId));
ListIterator<WebElement> wIterator = nearbyEvents.listIterator();
WebElement element = null;
String registerNowId = null;
while(wIterator.hasNext()) {
element = wIterator.next().findElement(By.linkText(QA_MOD_NONFULL_EVENT));
element.click();
registerNowId = element.getAttribute("onclick").replaceAll("\\D+", "");
}
registerNowId = "top30_" + registerNowId;
driver.findElement(By.xpath("//*[@id='" + registerNowId + "']/div[3]/div/a")).click();
WebElement dropDownListBox = driver.findElement(By.xpath("//*[@id='list']"));
Select clickThis = new Select(dropDownListBox);
clickThis.selectByValue("mod");
driver.findElement(By.xpath("//*[@id='situationdropdown']/div/div/div[1]/span/span/span/input")).click();
RegistrationForm.fillFormAndSubmit();
}
Code is just for the idea, but the problem is It is running in JUnit Test case why not using maven. It says tests : 0 runs : 0 skips : 0
Why it is not recognizing the tests, I am still not sure why? Can someone help?
Upvotes: 2
Views: 4315
Reputation: 48075
You say that your test class name ends with Tests. That is not one of the default patterns according to the surefire plugin site: http://maven.apache.org/plugins/maven-surefire-plugin/examples/inclusion-exclusion.html
**/Test*.java" - includes all of its subdirectories and all java filenames that start with "Test
**/*Test.java" - includes all of its subdirectories and all java filenames that end with "Test
**/*TestCase.java" - includes all of its subdirectories and all java filenames that end with "TestCase
Upvotes: 2