I have a created a login test for my website using the TestNG framework in Java in Eclipse and want to execute my tests through an XML file by running it through the command prompt.
The name of the website I want to test is named My Website. The root folder of my project is Test My Website
and the file system of my folder is illustrated in the following screenshot:
I have followed the instructions as given over here and have arranged my project's file system accordingly.
PS: A bin
folder also exists in my project's root which is used by the Java compiler to store the .class
files but is not displayed in the Eclipse's Package Explorer.
The source code of the TestClass1.java is,
package testngsample;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.testng.annotations.AfterClass;
public class TestClass1 {
protected static WebDriver driver;
protected static String result;
@BeforeClass
public void setup() {
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
@Test
void loginTest() {
try {
driver.get("https://test.rockon.me");
driver.findElement(By.id("btnLogin")).click();
driver.findElement(By.id("txtUserName")).sendKeys("max_marchisio");
driver.findElement(By.id("txtPassword")).sendKeys("Rockon123");
driver.findElement(By.id("GoArrow")).click();
Thread.sleep(15000);
result = driver.getTitle();
Assert.assertEquals(result, "Home | RockON");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@AfterClass
public void teardown() {
driver.close();
driver.quit();
}
}
The source code of the TestNG.xml file is,
<?xml version="1.0" encoding="UTF-8"?>
<suite name="My sample Suite">
<test name="Search test">
<classes>
<class name="TestClass1" />
</classes>
</test>
</suite>
The problem here is that despite following the proper instructions as given in the link provided above, I am unable to execute the TestNG.xml
file. In order to execute the file from command prompt, I am executing the following commands in my command prompt.
1) cd C:\Users\rugved.mandrekar\workspace\Test My Website
2) set ProjectPath="C:\Users\rugved.mandrekar\workspace\Test My Website"
3) set classpath=%ProjectPath%\bin;%ProjectPath%\lib\*
4) java -cp org.testng.TestNG %ProjectPath%TestNG.xml
and get the following output (literally) in my command prompt,
Error: Could not load find or load main class C:\Users\rugved.mandrekar\workspace\Test My Website"TestNG.xml
I am able to run the script by executing the TestNG.xml file through Eclipse by creating the TestNG run configuration for the file and it also produces the output and generates the reports perfectly, but why is this not happening from command prompt?
Can anyone please tell me where exactly am I going wrong? Replies at the earliest will be highly appreciated. Thank you.
No comments:
Post a Comment