简体   繁体   English

在Selenium Java中断言颜色值正确或不正确

[英]Assert color value is correct or not in selenium java

I am using selenium using java. 我正在使用Java使用硒。 I am new to selenium. 我是硒新手。 I have a class named connected which contains a symbol with green.I want to assert that if the symbol turned to green or not. 我有一个名为connect的类,其中包含带有绿色的符号。我想断言该符号是否变为绿色。

Here is my code:- 这是我的代码:

 Boolean connectionSymbolGreenValue = driver.findElement(By.className("connected")).isEnabled();
    System.out.println("Green Signal"+connectionSymbolGreenValue);
    Assert.assertTrue(connectionSymbolGreenValue);

I have tried this code. 我已经尝试过此代码。 If condition Fails then also it is returning true. 如果条件失败,则它也返回true。 Is there any error in my code? 我的代码中有任何错误吗? Can anyone suggest any solution? 有人可以提出任何解决方案吗?

As you are trying to identify a class named connected which contains a symbol with green invoking .isEnabled() method may not solve our purpose. 当您尝试标识名为connected的类时,该类包含带有绿色调用.isEnabled()方法的符号可能无法解决我们的目的。

.isEnabled()

.isEnabled() validates if the element currently enabled or not? .isEnabled()验证元素当前是否启用? This will generally return true for everything but disabled input elements. 对于除禁用的输入元素之外的所有内容,通常返回true

Solution

Try to identify an attribute(style) which uniquely identifies the attribute_containing_greenness_value of the symbol, then extract the String value and invoke Assert.assertTrue() comparing with actual_greenness_value as follows : 尝试识别一个属性(样式),该attribute_containing_greenness_value唯一地标识该符号的attribute_containing_greenness_value Assert.assertTrue() ,然后提取String值并调用Assert.assertTrue()并与actual_greenness_value进行比较,如下所示:

String connectionSymbolGreenValue = driver.findElement(By.className("connected")).getAttribute("attribute_containing_greenness_value");
System.out.println("Green Signal"+connectionSymbolGreenValue);
Assert.assertTrue(connectionSymbolGreenValue.equalsIgnoreCase("actual_greenness_value"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM