我正在尝试使用testng.xml运行我的TestNG套件。我的套件中总共有四个类,但是一次只能使用所有方法运行两个类。假设每个类中有3个方法,因此在TestNG套件中,如果仅添加两个类,则testng.xml文件将使用6个方法运行这两个测试。现在,如果我尝试在testng.xml文件中添加第3个类,则它将仅运行每个类中的第一个方法。这意味着它现在只运行3个方法(每个类一个)。我在项目下创建了一个源文件夹,然后在该源文件夹中创建了这个testng.xml文件。您能告诉我我做错了吗?下面是我的testng.xml文件和测试用例。
testng.xml在下面:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="MurcuryTour AUtomation suite">
<test name="MurcuryTour">
<classes>
<class name="murcuryTourPagesTests.LoginPageTest"></class>
<class name="murcuryTourPagesTests.FlightsPageTest"></class>
<class name="murcuryTourPagesTests.HomePageTest"></class>
</classes>
</test>
</suite>
Here is my all test classes that I am trying to run in test suite.
package murcuryTourPagesTests;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.MurcuryTour.qa.base.TestBase;
import com.MurcuryTour.qa.pages.FlightsPage;
import com.MurcuryTour.qa.pages.LoginPage;
public class LoginPageTest extends TestBase{
LoginPage loginpage;
FlightsPage flightspage;
public LoginPageTest() {
super();
}
@BeforeClass
public void setup() {
initialization();
loginpage = new LoginPage();
flightspage = new FlightsPage();
}
@Test(priority=1)
public void titleVerification() {
String title =loginpage.validatePageTitle();
Assert.assertEquals(title,"Sign-on: Mercury Tours");
}
@Test(priority=2)
public void login() {
flightspage =loginpage.login(prop.getProperty ("username"),prop.getProperty("password"));
}
@AfterClass
public void tearDown() {
driver.quit();
}
}
-----------------------------------------------------------
2nd class:
package murcuryTourPagesTests;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.MurcuryTour.qa.base.TestBase;
import com.MurcuryTour.qa.pages.HomePage;
import com.MurcuryTour.qa.pages.LoginPage;
import com.MurcuryTour.qa.pages.RegistrationPage;
public class HomePageTest extends TestBase {
LoginPage loginpage;
HomePage homepage;
RegistrationPage registrationPage;
public HomePageTest() {
super();
}
@BeforeTest
public void setup() {
initialization();
loginpage = new LoginPage();
loginpage.login(prop.getProperty("username"),prop.getProperty("password"));
homepage = new HomePage();
registrationPage = new RegistrationPage();
}
@Test(priority = 1)
public void click_On_Home_Tab() {
homepage.Click_On_Home_Tab();
}
@Test(priority = 2)
public void home_Page_Title_Verification() {
String title = homepage.Verify_HomePage_Title();
Assert.assertEquals(title, "Welcome: Mercury Tours");
}
@AfterSuite
public void tearDown() {
driver.close();
}
}
---------------------------------------------------------------------
3rd class:
package murcuryTourPagesTests;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.MurcuryTour.qa.base.TestBase;
import com.MurcuryTour.qa.pages.FlightsPage;
import com.MurcuryTour.qa.pages.HomePage;
import com.MurcuryTour.qa.pages.LoginPage;
public class FlightsPageTest extends TestBase{
LoginPage loginpage;
FlightsPage flightspage;
HomePage homepage;
public FlightsPageTest() {
super();
}
@BeforeClass
public void setup() {
initialization();
loginpage= new LoginPage();
loginpage.login(prop.getProperty("username"),prop.getProperty ("password"));
flightspage= new FlightsPage();
homepage= new HomePage();
}
@Test(priority=1)
public void verifyFlightsPageTitle() {
String title =flightspage.varifyFlightsPageTitle();
Assert.assertEquals(title,"Find a Flight: Mercury Tours:");
}
@Test(priority=2)
public void move_To_Find_A_FlightPage() {
flightspage.clickOnFindFlights();
}
@Test(priority=3)
public void move_To_Reservation_Page(){
flightspage.clickOnreserveFlights();
}
@Test(priority=4)
public void enter_User_Inofrmation() {
flightspage.enterUserInformation();
}
@Test(priority=5)
public void back_To_Home_Page(){
homepage=flightspage.backToHomePage();
}
@AfterClass
public void tearDown() {
driver.quit();
}
}