无法捕获异常

can't catch Exception

当我开始我的测试时,我想看到一个异常,但程序只停留在一行 "mobileTelephony.driver" 并且没有通过异常。我不明白为什么?

@Test(groups = {"non-basic"})
@Parameters({"idCategory"})
public void checkSearchForm(int idCategory) throws InterruptedException {


String categoryName;
    int location = 1;
    StackOfCategories sub1Stack = TestSuiteMobileTelephony.sub1Stack;   
    boolean isItSubCategory;

basePage.getBasePage();

basePage.clickCategoryName(idCategory);
MobileTelephonyPage mobileTelephony = PageFactory.initElements(basePage.driver, MobileTelephonyPage.class);

while (location <= 3) {
    mobileTelephony.clickChangeLocation(location);
    for(int i = 1; i <= sub1Stack.size(); i++) {
        if (location == 1) {
            categoryName = sub1Stack.getCategory(i).getNameEn();
        } else if (location == 2) {
            categoryName = sub1Stack.getCategory(i).getNameRu();
        } else {
            categoryName = sub1Stack.getCategory(i).getNameUk();
        }

        mobileTelephony.writeInSearchFormAndClick(categoryName);

        try {
            mobileTelephony.driver.findElement(By.xpath(".//div[@id='breadcrumbs']/span1"));
        } catch(Exception e){
            e.printStackTrace();
            mobileTelephony.back();
        }
        isItSubCategory = true;

        AssertMessage.assertTrueNavigateSubCategory(categoryName, isItSubCategory);
        mobileTelephony.back();
    }
    location++;
}

} Mobail电话代码 public class MobileTelephonyPage 扩展了 BasePage {

public void clickAndWriteNumber(String number) throws AWTException {

    String[] numsArray = number.split("");

    number1.clear();
    number1.click();
    Robot robot = new Robot();
    // Constryction
    for(int i = 0; i < numsArray.length; i++) {

        switch(Integer.parseInt(numsArray[i])) {
            case 0 :
                robot.keyPress(KeyEvent.VK_0);
                break;
            case 1 :
                robot.keyPress(KeyEvent.VK_1);
                break;
            case 2 :
                robot.keyPress(KeyEvent.VK_2);
                break;
            case 3 :
                robot.keyPress(KeyEvent.VK_3);
                break;
            case 4 :
                robot.keyPress(KeyEvent.VK_4);
                break;
            case 5 :
                robot.keyPress(KeyEvent.VK_5);
                break;
            case 6 :
                robot.keyPress(KeyEvent.VK_6);
                break;
            case 7 :
                robot.keyPress(KeyEvent.VK_7);
                break;
            case 8 :
                robot.keyPress(KeyEvent.VK_8);
                break;
            case 9 :
                robot.keyPress(KeyEvent.VK_9);
                break;
        }
    }       
}

public MobileTelephonyPage(WebDriver driver) {
    super(driver);
}

public int getHeightImg(int number) {
    int height = driver.findElement(By.xpath("(.//div[@class='icon']/img)[" + number + "]")).getSize().getHeight();
    return height;  
}

public int getWidthImg(int number) {
    int width = driver.findElement(By.xpath("(.//div[@class='icon']/img)[" + number + "]")).getSize().getWidth();
    return width;
}

public MobileTelephonyPage back() {
    driver.navigate().back();
    return this;
}

public String getCurrentURL() {
    return driver.getCurrentUrl();
}

public void clickOperator(String linkText) {
    driver.findElement(By.linkText(linkText)).click();
}

}

调试程序在下一个代码片段中停止(class HttpCommandExecutor)

    this.log("profiler", new HttpProfilerLogEntry(command.getName(), true));
    HttpResponse e = this.client.execute(httpRequest, true);
    this.log("profiler", new HttpProfilerLogEntry(command.getName(), false));

没有抛出异常。

可能代码需要很长时间才能执行或者处于活锁状态。

A livelock 是函数执行但永远不会结束的情况。例如,因为在 for 循环中,您松散地更新了一个变量,所以测试始终为真

根据新信息进行编辑

来自 WebDriver 的 javadoc:

This method is affected by the 'implicit wait' times in force at the time of execution. The findElement(..) invocation will return a matching row, or try again repeatedly until the configured timeout is reached. findElement should not be used to look for non-present elements, use findElements(By) and assert zero length response instead.

如您所见,函数无法 returns 与我的 post.

前两行中提到的完全相同