在这种情况下,我只是想使用dataprovider或任何其他可能的方式迭代所有环境。请参阅我的连接Excel文件如何从excel获取URL到@BeforeTest使用DataDriven对不同Env使用TestNG测试
代码一个环境:下面给出LTI。注意:只需更改类名称即可为所有其他环境重复使用相同的代码。
public class LTI_ENV {
public WebDriver driver;
private String sTestCaseName;
private int iTestCaseRow;
@BeforeTest
public void beforeMethod() throws Exception {
DOMConfigurator.configure("log4j.xml");
// Getting the Test Case name, as it will going to use in so many places
// The main use is to get the TestCase row from the Test Data Excel sheet
sTestCaseName = this.toString();
// From above method we get long test case name including package and class name etc.
// The below method will refine your test case name, exactly the name use have used
//Here I want to parameterize URL for each test ,is there any method that I can do ???
//My application have 3 module i.e for LTI –Env
//1)Account Management (need to check pass?fail)
//2)Prep and rating (need to check pass?fail)
//3)Risk Eval (need to check pass?fail)
sTestCaseName = Utils.getTestCaseName(this.toString());
Log.startTestCase(sTestCaseName);
ExcelUtils.setExcelFile(Constant.Path_TestData + Constant.File_TestData,"Sheet1");
iTestCaseRow = ExcelUtils.getRowContains(sTestCaseName,Constant.Col_TestCaseName);
driver = Utils.OpenBrowser(iTestCaseRow);
new BaseClass(driver);
}
@Test(priority=1)
public void AccountManagement() throws Exception {
try {
AccountCreation_Action.Execute(iTestCaseRow);
AM_SubmissionLOB_Action.Execute(iTestCaseRow);
AM_Classification_Action.Execute(iTestCaseRow);
//Verification_Action1.Execute();
if (BaseClass.bResult==true) {
ExcelUtils.setCellData("Pass", iTestCaseRow, Constant.Col_ResultStatus);
} else {
throw new Exception("Test Case Failed because of Verification");
}
} catch (Exception e) {
ExcelUtils.setCellData("Fail", iTestCaseRow, Constant.Col_ResultStatus);
Utils.takeScreenshot(driver, sTestCaseName);
// This will print the error log message
Log.error(e.getMessage());
// Again throwing the exception to fail the test completely in the TestNG results
throw (e);
}
}
@Test(priority=2,dependsOnMethods="AccountManagement")
public void PrepandRating() throws Exception {
try {
GenInfopage_Action.Execute(iTestCaseRow);
LocationSchedulePage_Actions.Execute(iTestCaseRow);
PolicyCoveragePage_Action.Execute(iTestCaseRow);
LocationInfo_Page_Action.Execute(iTestCaseRow);
LocationSchedulePage_Actions.Execute(iTestCaseRow);
AutoVehicleCoveragePage_Action.Execute(iTestCaseRow);
AutoPolicyCoveragePage_Action.Execute(iTestCaseRow);
PremiumSummaryPage_Action.Execute(iTestCaseRow);
//Verification_Action2.Execute();
if (BaseClass.bResult==true) {
ExcelUtils.setCellData("Pass", iTestCaseRow+2, Constant.Col_ResultStatus);
} else {
throw new Exception("Test Case Failed because of Verification");
}
} catch (Exception e) {
ExcelUtils[enter image description here][1].setCellData("Fail", iTestCaseRow+2, Constant.Col_ResultStatus);
Utils.takeScreenshot(driver, sTestCaseName);
Log.error(e.getMessage());
throw (e);
}
}
@Test(priority=3,dependsOnMethods="PrepandRating")
public void RiskEval() throws Exception {
//will update code for this module
}
// Its time to close the finish the test case
@AfterTest
public void afterTest() {
// Printing beautiful logs to end the test case
Log.endTestCase(sTestCaseName);
// Closing the driver
driver.quit(); //I need to close all the browser and then will launch again for other environment tests
}
}
挑战,我面对的是:
在上面的代码,我先在Excel中
TestCaseName
列使用Utils.getTestCaseName(this.toString());
因此,在这里我可以只运行一个环境搜索测试案例名称一次。我想,如果我的测试运行状态RUN /运行测试用例否则跳过
我怎样写用TestNG这种情况?和@BeforeTest
一样,我需要为每个测试环境获取URL。
请从下面的框架,我已经实现:http://toolsqa.wpengine.com/selenium-webdriver/selenium-automation-hybrid-framework
你为什么不动该配置了Excel中的文件转换成更容易些什么呢? – jonrsharpe
其实,这是我每日Smoketest设置...为了更多的用户友好,我想保持这个检查点(Run/Norun)在Excel文件中。 我想写这种方式设置一些reggression .. 是否有任何其他的解决方案呢? –
我还尝试将所有测试用例的Xml文件路径(即LTI.xml,PTE,.xml,LTQ.xml,INT.xml)保存到各自的excel行中,然后使用dataprovider将Run状态和XML路径作为参数。 –