"Type mismatch: cannot convert from void to boolean" 断言
"Type mismatch: cannot convert from void to boolean" on assert
代码如下:
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class ContactPageElements {
public static WebElement element = null;
public static String baseURL1 = "http://something.com";
//Clicking logo should take you back to the baseURL
public static void clickLogo (WebDriver driver) {
element = driver.findElement(By.xpath(".//*[@id='blah'"));
element.click();
String currentURL = driver.getCurrentUrl();
assert.assertEquals(currentURL, baseURL1);
}
}
对于断言,我收到一个错误:"Type mismatch: cannot convert from void to boolean"
鉴于您对 assertEquals()
进行了静态导入,clickLogo()
的最后一行应该只是:
assertEquals(currentURL, baseURL1);
代码如下:
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class ContactPageElements {
public static WebElement element = null;
public static String baseURL1 = "http://something.com";
//Clicking logo should take you back to the baseURL
public static void clickLogo (WebDriver driver) {
element = driver.findElement(By.xpath(".//*[@id='blah'"));
element.click();
String currentURL = driver.getCurrentUrl();
assert.assertEquals(currentURL, baseURL1);
}
}
对于断言,我收到一个错误:"Type mismatch: cannot convert from void to boolean"
鉴于您对 assertEquals()
进行了静态导入,clickLogo()
的最后一行应该只是:
assertEquals(currentURL, baseURL1);