I don't quite understand why java is pointing to the last instance of the "we" variable in the code below and telling me that it might not be initialized. The initialization happens in the first try catch. The second try catch is nested under the first try catch. Why is it complaining?
public void runTests() {
int testIndex;
WebElement we;
//Test 1 - Unchecking County Lines
testIndex=1;
if (testTest[testIndex]) {
printTestStart(testIndex);
//FIRST TEST:
try {
//* MAIN TEST LOGIC GOES HERE **************************
we = driver.findElement(By.id("chkCounties"));
we.click();
//* MAIN TEST LOGIC GOES HERE **************************
this.testPassed[testIndex] = this.getPassFail(testIndex);
} catch (Exception e) {
testPassed[testIndex] = false;
}
//DEPENDANT TEST:
testIndex +=1;
if (testPassed[testIndex-1] && testTest[testIndex]) {
try {
//* MAIN TEST LOGIC (Dependant Test) GOES HERE *********
we.click();
//* MAIN TEST LOGIC (Dependant Test) GOES HERE *********
this.testPassed[testIndex] = this.getPassFail(testIndex);
} catch (Exception ee) {
testPassed[testIndex] = false;
}
}
}
testIndex=3;
}