有没有一种方法可以根据条件继续执行或退出硒测试用例?

时间:2020-07-07 22:28:19

标签: java selenium-webdriver

@Test
public void newMerchant() throws InterruptedException {
    // click the merchant menu link
    driver.findElement(By.xpath("/html/body/div/div/div[1]/ul/li[1]/a")).click();
    // Click the add new button
    Thread.sleep(10000);
    driver.findElement(By.xpath("/html/body/div/div/div[2]/div[1]/a")).click();
    Thread.sleep(10000);
    // Fill in the details of a merchant
    driver.findElement(By.id("FirstName")).sendKeys("Tester2");
    driver.findElement(By.id("LastName")).sendKeys("Excel");
    driver.findElement(By.id("Address")).sendKeys("7, Cole Street");
    driver.findElement(By.id("PhoneNumber")).sendKeys("234798889");
    driver.findElement(By.id("Email")).sendKeys("tayotester@gmail.com");
    // Save details
    driver.findElement(By.xpath("/html/body/div/div/div[2]/div/form/button")).click();
    String actual = driver.findElement(By.className("toast-message")).getText();
    System.out.println("The message is: " + actual);
    if(actual == "Merchant Creation Successful" ) {
        newTC();
    }
    else {
        newMerchant();
    }
    String expected = "Merchant Creation Successful";
    Assert.assertEquals(actual, expected);

}

@Test
public void newTC() throws InterruptedException {

    // click the merchant menu link
    driver.findElement(By.xpath("/html/body/div/div/div[1]/ul/li[1]/a")).click();
    // Click the add new button
    Thread.sleep(1000);
    driver.findElement(By.xpath("/html/body/div/div/div[2]/div[1]/a")).click();
    driver.findElement(By.linkText("Kiosk Setup")).click(); 

}

如果不满足“如果条件”,我希望代码执行newMerchant();如果满足“如果条件”,我将转到另一个newTC方法。任何帮助将不胜感激。

0 个答案:

没有答案