dar*_*ale 0 java testng selenium font-family
我正在使用Selenium-server-standalone-3.141.59.jar文件和testNG 版本 6.14.3。使用它,我想比较 Web Element font-family 作为输入硬编码值,并使用 selenium driver.findElement从网站获取。现在我已经制作了方法SoftAssert代码
这是我尝试过的SoftAssert。创建方法并作为参数传递WebElement obj, fontNameValid作为值ProximaNova。现在我从HTML得到font-family是 ' ProximaNova-Light ' 理想情况下,一旦我们添加assertEqual方法,SoftAssert 应该将此检测为错误,但它会通过测试用例。请帮忙。
CheckCSS.java
public static SoftAssert webElement_Check_CSS(WebElement obj, String fontNameValid) {
String fontName1 = obj.getCssValue("font-family");
System.out.println("Font Name from HTML :------->" + fontName1);
System.out.println("Font Name as input :------->" + fontNameValid);
softAssert.assertEquals(fontNameValid, fontName1,"WebElement is ["+obj.getText()+"] and Font name is not as per visuals");
}
DemoTest.java
@Test
public void Header(){
System.out.println("++++++contactno+++++++++");
String fontFamily ="proximanova";
WebElement contact = driver.findElement(By.xpath("/html/body/form/div[3]/div[2]/a[2]"));
softAssert = CheckCSS.webElement_Check_CSS(contact,fontFamily);
//contact.click();
}
Run Code Online (Sandbox Code Playgroud)
Starting ChromeDriver 76.0.3809.68 (420c9498db8ce8fcd190a954d51297672c1515d5-refs/branch-heads/3809@{#864}) on port 36987
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1569829278.198][WARNING]: This version of ChromeDriver has not been tested with Chrome version 77.
Sep 30, 2019 1:11:19 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
++++++contact no+++++++++
Font Name from HTML :------->ProximaNova-Light
Font Name as input :------->proximanova
Font Size:-------->15px
rgba(255, 232, 214, 1)
Font colour converted to hex:#ffe8d6
text-align:-------->center
PASSED: Header
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
Run Code Online (Sandbox Code Playgroud)
你缺少的是
softAssert.assertAll();
这将在运行所有与 softassert 相关的断言测试后给出一次结果。
SoftAssert softAssert = new SoftAssert();
String ActualErrorMEssage = firstNameerrorXpath.getText;
String ActualErrorMEssage2 = secondNameNameerrorXpath.getText;
softAssert.assertEquals(ActualErrorMEssage,ExpectedErrorMEssage);
softAssert.assertEquals(ActualErrorMEssage2,ExpectedErrorMEssage);
softAssert.assertAll();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
64 次 |
| 最近记录: |