参数closeApplication的非法修饰符;只有决赛是允许的

时间:2018-02-22 14:05:05

标签: selenium selenium-webdriver testng

我创建了一个名为BaseClass的类,它将在InvalidLogin类中进行扩展。在BaseClass类中,有一个方法显示以下错误消息:

此行有多个标记      - 语法错误,插入“;”完成LocalVariableDeclarationStatement      - 语法错误,插入“[]”以完成维度      - 令牌“closeApplication”上的语法错误,预期后的AnnotationName      这个标记      - void []是无效类型      - 参数closeApplication的非法修饰符;只允许决赛

以下是上面引用的类和Eclipse提供的错误图像。

    public class BaseClass {

    WebDriver driver;
    @BeforeClass
    public void setupApplication() {
        Reporter.log("Instanciando o navegador", true);
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("http://enterprise.demo.orangehrmlive.com/symfony/web/index.php/auth/login");
        Reporter.log("Aplicação inicializada", true);

        @AfterClass
        public  void closeApplication() {
            driver.quit();
            Reporter.log("Sessão do navegador finalizada");
        }       
    }
}


    public class InvalidLogin extends BaseClass {

    @Test(description = "This Test Case will perform valid login")
    public void loginApplicationValid() {
        try {
            driver.findElement(By.name("txtUsername")).sendKeys("Admin1");
            driver.findElement(By.id("txtPassword")).sendKeys("admin1");
            driver.findElement(By.id("btnLogin")).click();
            driver.navigate().back();
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    @Test(description = "This Test Case will perform invalid login")
    public void loginApplicationInvalid() {
        driver.findElement(By.name("txtUsername")).sendKeys("admin1");
        driver.findElement(By.id("txtPassword")).sendKeys("admin2");
        driver.findElement(By.id("btnLogin")).click();
    }
}

Print Erro

Print Erro 2

1 个答案:

答案 0 :(得分:1)

您没有正确关闭方法setupApplication。只需在方法closeApplication之前添加结束括号,如下所示。

public class BaseClass {

WebDriver driver;
@BeforeClass
public void setupApplication() {
    Reporter.log("Instanciando o navegador", true);
    driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.get("http://enterprise.demo.orangehrmlive.com/symfony/web/index.php/auth/login");
    Reporter.log("Aplicação inicializada", true);
    }

    @AfterClass
    public  void closeApplication() {
        driver.quit();
        Reporter.log("Sessão do navegador finalizada");
    }       

}