Getting ArrayIndexOutOfBoundsException After completing the Test Execution


#1

The feature file execution in a project is working fine. When I copied the same project into Git, it is executing all the steps properly but in the end, it is throwing " Keyword runFeatureFile was failed (Root cause: java.lang.ArrayIndexOutOfBoundsException: 20)" Error.

Below is the Feature File and Step Definition for the same:

Feature: Feeding the data to the Table Parking

#Sceanrio-1:
@SmokeTest
Scenario: Feeding the data to the Table Parking
Given User can see the Table Parking
And User enters the details of MaterialDescription, SRI, Initial and parking spaces in Spaces covered by high-reflectance roof for the required number of times
And User can enter the values of spaces covered by energy generation, vegetated roof, building or deck in table parking
When User can see the value in Total number of qualifying parking spaces
And User can enter the Total number of parking spaces
Then User can see the values in Percentage of compliant parking spaces in Table Parking
And User Enters the Value in Total area of vegetated roof

//#######StepDef######################

class Table_Parking {

TestObject material_parking, SR_parking, Initial_parking, Numberofparkingspaces, parking_row
int k

DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a");


@Given("User can see the Table Parking")
public void user_can_see_the_Table_Parking() {
	
	WebUI.callTestCase(findTestCase('Test Cases/HeatIslandReduction/Table_HighReflectanceRoof'),null, FailureHandling.STOP_ON_FAILURE)
	WebUI.verifyElementPresent(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/div_Table Parking'), 0)
}

@And("User enters the details of MaterialDescription, SRI, Initial and parking spaces in Spaces covered by high-reflectance roof for the required number of times")
public void user_enters_the_details_of_MaterialDescription_SRI_Initial_and_parking_spaces_in_Spaces_covered_by_high_reflectance_roof_for_the_required_number_of_times() {
	
	Date date = new Date()
	String tablestart= dateFormat.format(date)

	println "Parking starting : "+tablestart

	WebUI.clearText(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/Material _Spaces_Table_parking'))
	WebUI.setText(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/Material _Spaces_Table_parking'), 'parking001')

	WebUI.clearText(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/SRI_Spaces_Table_parking'))
	WebUI.setText(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/SRI_Spaces_Table_parking'), '55')

	WebUI.selectOptionByValue(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/Initial_Spaces_Table_parking'), '3 Year Aged', true)

	WebUI.clearText(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/Numberofspaces_Spaces_Table_Parking'))
	WebUI.setText(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/Numberofspaces_Spaces_Table_Parking'), '23')

	WebUI.click(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/btn_Add_parking'))


	for(def row=1; row <=findTestData("HeatIsland_Nonroof/Parking").getRowNumbers();row++) {
		/////////incrementing the rows/////////

		k=row+1
		println k
		WebUI.switchToFrame(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/iframe'), 5)
		material_parking = new TestObject().addProperty('xpath', ConditionType.EQUALS, '//*[@id="credit-form"]/div[3]/div[3]/div/table/tbody/tr['+k+']/td[1]/input', true)

		SR_parking = new TestObject().addProperty('xpath', ConditionType.EQUALS, '//*[@id="credit-form"]/div[3]/div[3]/div/table/tbody/tr['+k+']/td[2]/input', true)
		Initial_parking= new TestObject().addProperty('xpath', ConditionType.EQUALS, '//*[@id="credit-form"]/div[3]/div[3]/div/table/tbody/tr['+k+']/td[3]/select', true)
		Numberofparkingspaces= new TestObject().addProperty('xpath', ConditionType.EQUALS, '//*[@id="credit-form"]/div[3]/div[3]/div/table/tbody/tr['+k+']/td[4]/input', true)

		////////////////////////////////////////////////////////////////////////////////


		WebUI.setText(material_parking, findTestData("HeatIsland_Nonroof/Parking").getValue("material", row))
		WebUI.setText(SR_parking, findTestData("HeatIsland_Nonroof/Parking").getValue("SRI", row))
		WebUI.selectOptionByValue(Initial_parking, findTestData("HeatIsland_Nonroof/Parking").getValue("Initial", row), true)
		WebUI.setText(Numberofparkingspaces, findTestData("HeatIsland_Nonroof/Parking").getValue("spaces", row))

		WebUI.switchToDefaultContent()

		////////////////////////////////////////////////

		int j=row+1
		println j

		parking_row = new TestObject().addProperty('xpath', ConditionType.EQUALS, '//*[@id="credit-form"]/div[3]/div[3]/div/table/tbody/tr['+j+']/td[5]/a[1]/i', true)
		
		WebUI.delay(1)
		if(row !=findTestData("HeatIsland_Nonroof/Parking").getRowNumbers())
		{
			WebUI.switchToFrame(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/iframe'), 5)
			WebUI.click(parking_row)

			WebUI.switchToDefaultContent()
		}
	}

	Date date1 = new Date()
	String tableEnd= dateFormat.format(date1)
	println "Parking Ending : "+tableEnd
}

@And("User can enter the values of spaces covered by energy generation, vegetated roof, building or deck in table parking")
public void user_can_enter_the_values_of_spaces_covered_by_energy_generation_vegetated_roof_building_or_deck_in_table_parking() {

	WebUI.setText(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/energygene_Parking'), "25")
	WebUI.setText(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/vegetatedroof_parking'), "35")
	WebUI.setText(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/undergroundorDeck_parking'),"55")

	WebUI.click(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/Total_areaVegetated_Parking'))

}

@When("User can see the value in Total number of qualifying parking spaces")
public void user_can_see_the_value_in_Total_number_of_qualifying_parking_spaces() {

	WebUI.verifyElementPresent(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/total_parking_Spaces'), 30)

}

@And("User can enter the Total number of parking spaces")
public void user_can_enter_the_Total_number_of_parking_spaces() {

	WebUI.setText(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/TotalNumberOfParking'), "58")

	WebUI.click(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/Total_areaVegetated_Parking'))
}

@Then("User can see the values in Percentage of compliant parking spaces in Table Parking")
public void user_can_see_the_values_in_Percentage_of_compliant_parking_spaces_in_Table_Parking() {

	WebUI.verifyElementPresent(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/percentage_spaces_parking'), 30)

}

@And("User Enters the Value in Total area of vegetated roof")
public void user_Enters_the_Value_in_Total_area_of_vegetated_roof() {

	WebUI.setText(findTestObject('Object Repository/HeatIslandMeasure/Table_Parking/Page_LEED Online/Total_areaVegetated_Parking'), "20")

	println "Table parking End"
}

}

@devalex88
Can you help me to resolve this issue

Thanks in Advance


#2

Has any one got this issue resolved ?


#3

The solution is to add an empty line + a comment line at the end of the file.
It fixes the index of Cucumber feature file.

I didn’t test with Example table, but I think as long as there’s an empty line + something else after the Scenario definition it should be OK.