2

Firstly I would like to point out that I'm a beginner when it comes to selenium so I apologise if this is not presented appropriately.

I would like to incorporate data driven testing into my ui_automation project. Our product validates data and returns various information about said data.

I have incorporated both csv and excel utilities to achieve this and currently have a @test that loops through 12 possible login attempts and then asserts against the result in the excel sheet (if login was successful or not). Now all the tests pass but it treats all the individual tests (the different rows of possible combinations and assertions) as one big test.

My question is I could potentially have hundreds of rows of data going into similar loops later on, should one fail the test case fails as a whole (which is not an issue) but how do you determine which record it was that failed so it can be quickly debugged or raised as a defect?

I was thinking of maybe an event listener that waits for assertions fail and then I could produce some sort of Log message but I dont know if this is effective and more to the point WebDriverEventListener does not contain a method for 'assertionFail' so that felt like a brickwall.

It would be great if there was a magic wand for this but I was just hoping there were some valid solutions you guys had that at least let me know it was possible.

I have included my loop code basically I want it to treat each loop as a sub test of the main test if its possible and get some sort of acknowledgement as to which test fails that is readable to a fellow QA team member that will view things from a high level point of view.

@Test
public void loginValidationTest() throws Exception {
 cellRow = 2;
 str = ExcelUtility.getCellData(cellRow, 0);
 while(str != "End of Data"){
 login.setUsernameTB(ExcelUtility.getCellData(cellRow, 1));
 login.setPasswordTB(ExcelUtility.getCellData(cellRow, 2));
 login.clickLoginBT();
 str = ExcelUtility.getCellData(cellRow, 4);
 if(str.equals("Y")){
 Assert.assertTrue("Login Unsuccessful", login.assertSuccessfulLogin());
 dashboard.clickLogoutBT();
 }else{
 by = By.xpath(ExcelUtility.getCellData(cellRow, 5));
 login.waitForElementToBeVisible(by);
 Assert.assertTrue("Login Successful", login.getElement(by).isDisplayed());
 login.clearLoginBoxes();
 }
 cellRow++;
 str = ExcelUtility.getCellData(cellRow, 0);
 }
}

Thanks in advance (and sorry for the shabby coding).

asked Mar 18, 2016 at 15:26
3
  • You'll want to add a tag to mention the language you are using for your code. Additionally, regardless of the language, why do you want to read from an excel file? If it's something external you are handed then you cannot count on the quality of the test data so you want to take control of it and use a form better suited to the language. If you have full control over the test data, then an excel file is not the most versatile option available to you. Commented Mar 18, 2016 at 15:36
  • Cheers Cronax have added Java and JUnit tags now. The issue is as a new member of a QA team I have taken it upon myself to try and implement this. now not all the QA guys are code savvy so my boss has requested using excel sheets so that other guys can come along and maintain the data rather than the framework. Commented Mar 18, 2016 at 15:49
  • If formatted properly, a text file should be perfectly understandable to anyone, and it pretty much eliminates the potential problems that excel files would have. Even a csv file would be better than straight excel for most languages although I must confess I am not the most knowledgeable person when it comes to Java Commented Mar 18, 2016 at 16:04

1 Answer 1

0

By using Parameterized Tests you should be able to achieve your desired results.

By adding something similar to the following:

@Parameters
public static List<Object> data() {
 List<Object> data = new ArrayList<Object>();
 cellRow = 2;
 while(str != "End of Data"){
 data.add(ExcelUtility.getRowData(cellRow));
 }
 return data;
}

And then pass in the data to the @Test method

answered Apr 11, 2016 at 13:06
1
  • 1
    :-) Brilliantly simple answer. Thank you very much and sorry for the delayed response! Commented Aug 10, 2016 at 9:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.