在下面的腳本中,我想先運行測試'登錄'然後'創建公司'。但是每當我嘗試運行腳本時,控件首先會轉到'CreateCompany'測試。並且由於用戶尚未登錄,腳本執行失敗。請有人告訴我下面的腳本有什麼問題。在Selenium TestNG中首先執行的錯誤測試
package MyPackage;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import MyPackage.PageObjects.CompanyListing;
import MyPackage.PageObjects.LoginPage;
public class SetUpCompany {
public static WebDriver driver;
public String BaseURL=LoginPage.BaseURL();
@BeforeClass
public static void setup() {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
//public static WebDriver driver = new FirefoxDriver();
@Test(dataProvider="UserData")
void Login(String username, String password, String usertype){
//dr.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
if(usertype.equals("SuperAdmin")){
String LoginURL=BaseURL+"/Manage";
driver.get(LoginURL);
LoginPage.UsernameBox(driver).sendKeys(username);
LoginPage.PasswordBox(driver).sendKeys(password);
LoginPage.LoginButton(driver).click();
//System.out.println("Hello Super admin!");
}
}
@Test(dataProvider="CompanyData")
void CreateCompany(String FrstNm, String LastNm, String CmpnyNm, String Email, String Phone, String Cell, String Web){
System.out.println("I'm here");
String ManageCompanyURL=BaseURL+"/Manage/Company";
driver.get(ManageCompanyURL);
CompanyListing.AddCmpnyBtn(driver).click();
}
@DataProvider(name="UserData")
public Object[][] loginData() {
Object[][] LoginArray = DataReader.getExcelData("E:/DataBase.xls","LoginData");
return LoginArray;
}
@DataProvider(name="CompanyData")
public Object[][] CompanyInfo() {
Object[][] CompanyArray = DataReader.getExcelData("E:/DataBase.xls","CompanyInfo");
return CompanyArray;
}
@AfterClass
public static void teardown() {
driver.close();
driver.quit();
}
}