【发布时间】:2016-02-01 03:07:34
【问题描述】:
我有一个图像在一定宽度尺寸后变得不可见。我不确定如何使用 selenium 进行测试。
<img id="removeimg" class="col-md-5" src="images/abc-image.png" alt="abc">
以下是我的css。
@media only screen and (max-width: 991px) {
#removeimg {
display: none;
}
为此,我有以下测试 java。但我不确定这是不是正确的做法。
@BeforeClass
public static void setUp() throws Exception {
driver = new RemoteWebDriver(new URL(System.getProperty("webDriverUrl")), DesiredCapabilities.firefox());
driver.manage().window().setSize(new Dimension(991, 1100));
baseUrl = System.getProperty("baseUrl");
driver.get(baseUrl + "/");
}
@Test
public void testImageNotPresent(){
driver.findElements(By.id("removeimg");
}
更新
我已向我的测试 java 添加了更新。
@Test
public void testImageNotPresent(){
driver.findElement(By.id("removeimg")).isDisplayed();
assertFalse(isElementPresent(By.id("removeimg")));
}
但这在运行时会失败。如果图片没有显示在页面上,我希望它通过测试,但如果显示失败。
【问题讨论】: