使用Selenium和Eclipse(Java)为表边框断言css样式

使用Selenium和Eclipse(Java)为表边框断言css样式,java,css,selenium,assert,Java,Css,Selenium,Assert,我正在测试一个表单,测试的一部分是将必填字段留空,并检查该字段是否有一个红色边框,表明该字段是必填字段,应在继续之前填写。到目前为止,我已获得以下代码: driver=new FirefoxDriver(); driver.manage().window().maximize(); /** Test: Open page*/ driver.get ("URL with form"); /** the following confirms a text above the form stati

我正在测试一个表单,测试的一部分是将必填字段留空,并检查该字段是否有一个红色边框,表明该字段是必填字段,应在继续之前填写。到目前为止,我已获得以下代码:

driver=new FirefoxDriver();
driver.manage().window().maximize();

/** Test: Open page*/
driver.get ("URL with form");

/** the following confirms a text above the form stating what fields are mandatory and not filled */
driver.findElement(By.id("nextbutton")).click(); /** leave all fields blank and click on next below form */
assertEquals("The following fields are mandatory", driver.findElement(By.cssSelector("p")).getText());
assertEquals("Field 1 is mandatory", driver.findElement(By.xpath("//form[@id='genericform']/div[2]/ul/li")).getText());
assertEquals("Field 2 is mandatory", driver.findElement(By.xpath("//form[@id='genericform']/div[2]/ul/li[2]")).getText());
assertEquals("Field 3 is mandatory", driver.findElement(By.xpath("//form[@id='genericform']/div[2]/ul/li[3]")).getText());

assertTrue(isElementPresent(By.id("Field1.Value"))); /** confirms the first mandatory field is present */
现在我想确认/断言必填字段有红色边框和图标,而非必填字段没有红色边框或图标。

CSS:
边框颜色:#E04228; 背景:#FFF url(“../img/icon field error.png”)无重复滚动右中心/28px 22px

我正在使用Eclipse和Selenium webdriver

使用方法获取
边框底色
边框顶色
边框左颜色
边框右颜色
CSS属性:

assertEquals("rgba(224, 66, 40)", element.getCssValue("border-bottom-color"));
请注意,
边框颜色
是,并且不能通过这种方式检索

您还可以尝试使其更具可读性和方便性


或者,您可以只检查
输入
元素是否有
错误
输入验证错误
类:

assertEquals("block error input-validation-error", element.getAttribute("class"));

谢谢你,上次更新成功了。我不得不改变一件事,但现在代码是:

assertEquals("rgba(224, 66, 40, 1)", driver.findElement(By.id("frm-Voornaam.Value")).getCssValue("border-bottom-color"));

我不得不用rgba做广告[1],现在它成功了,谢谢

我尝试添加代码:assertEquals(“#E04228”,driver.findelelement(By.id(“frm Voornaam.Value”)).getCssValue(“border color”);但是这导致了:org.junit.ComparisonFailure:expected:但是:…@Hugo那么,基本上它根本没有读取
边框颜色设置?您确定在做出断言时突出显示了输入吗?谢谢。这是完整的CSS部分:select.error,textarea.error,input[type=“email”]。error,input[type=“password”]。error,input[type=“tel”]。error,input[type=“url”]。error,input[type=“date”]。error,input[type=“datetime”]。error,input[type=“datetime local”]。error,input[type=“DATETER=“月”]。错误,输入[type=“time”]。错误,输入[type=“week”]。错误,输入[type=“search”]。错误{边框颜色:#e04228;背景:#fff url(../img/icon field error.png)不重复,对;背景大小:28px 22px;页面中的源代码:@Hugo你知道吗,如果我们检查是否存在
错误
输入验证错误
类呢?。。