如何使用EaseTech,Selenium,java在Excel文件中编写测试结果和数据

时间:2014-07-08 11:09:22

标签: java excel selenium webdriver

@RunWith(DataDrivenTestRunner.class)
@DataLoader(filePaths = { "C:/eclipse/backendUserRegistration.xls" } , writeData=false)

public class UserLimitationPerCountryAndOperatorTest extends SeamlessBaseTest{

@Test
public void testLimitOfUsersOnOperators(@Param(name="country")String country ,
                                        @Param(name="limitation")String limitation) {
    OMBEBasePage basePage = loginOMBE();
    NewUserRegistrationPage registrationPage = basePage.goToNewUserRegistrationPage();
    registrationPage.createNewUser(country, "Noxwin");
    String account = registrationPage.getAccountCreatedConfirmationMessage();
    assertTrue(account.contains(" created"));
    String createdUser = account.split(" ")[0];
    System.out.println(createdUser);
    UserSearchPage userSearchPage = basePage.goToUserSearchPage();
    userSearchPage.searchByUserName(createdUser);
    String userLocalLimit = userSearchPage.getUserGeneralLocalLimit();
    assertEquals(limitation, userLocalLimit);
    userSearchPage.goToMyProfileTab();
    String userCountry = userSearchPage.countryOfUser();
    assertEquals(" "+country, userCountry);
}

@After
public void logoutAfterTest() {
    OMBEBasePage basePage = new OMBEBasePage(driver);
    basePage.logoutOMBE();
}

}

这是我编写的测试,它运行正常,我现在想要做的是在Excel文件中写入一列上的createdUser和另一列上的测试结果。< / p>

谢谢。

1 个答案:

答案 0 :(得分:0)

对于这个简单的场景,我想创建CSV文件并将其导入Excel将为您完成工作。所以写一下

try {
    FileWriter writer = new FileWriter("testResult.csv");
    writer.append(createdUser);
    writer.append(',');
    writer.append(testResult); //whatever String this is
    writer.flush();
    writer.close();
catch (IOException ex) {
    //handle exception somehow    
}

而不是将testResult.csv导入Excel,它应该为您提供一个包含两列的工作表 - 创建用户和测试结果。

如果您遇到一些复杂的情况,我建议您使用Apache POI库。