标签:bool set false cas tostring parent tun catch mis
package com.example.tests;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class UntitledTestCase {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@BeforeClass(alwaysRun = true)
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "https://www.katalon.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testUntitledTestCase() throws Exception {
driver.get("https://www.csdn.net/");
driver.findElement(By.linkText("下载")).click();
// ERROR: Caught exception [ERROR: Unsupported command [selectWindow | win_ser_1 | ]]
driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)=‘xiaobingge2018‘])[1]/following::span[3]")).click();
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=0 | ]]
driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)=‘基本‘])[1]/following::span[1]")).click();
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame | relative=parent | ]]
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=1 | ]]
driver.findElement(By.id("conn_status")).click();
// ERROR: Caught exception [ERROR: Unsupported command [selectWindow | win_ser_1 | ]]
acceptNextAlert = true;
driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)=‘子网掩码‘])[1]/following::input[2]")).click();
assertEquals(closeAlertAndGetItsText(), "要重新建立连接,请单击连接按钮");
driver.findElement(By.name("connect")).click();
}
@AfterClass(alwaysRun = true)
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
标签:bool set false cas tostring parent tun catch mis
原文地址:https://www.cnblogs.com/jnhs/p/10205531.html