0

I have a Selenium suite testing my (web) user interface and I'm trying to prove that the appropriate error messages appear when a User puts in invalid values.

<input id="inputID" type="number" min="1" step="1" />

WebElement element = webDriver.findElement(By.id("inputID"));
element.click();
element.sendKeys("-2");
element.??????

It's trivial to do by hand, but for the life of me I can't figure out how to test that the input:invalid CSS is applied or how to read/test the tooltip value.

It would probably be sufficient to prove that the field is marked as invalid, even if we don't test the content of the tooltip, though ideally we'd test both.

9
  • If give invalid data do you get any warning... Commented Mar 15, 2018 at 17:21
  • The "min" attribute might not mean to you what the programmer intended it to mean. It may not be a minimum value, but a minimum length (in characters). Typically, you should test according to the acceptance criteria you, as the tester, are given. Commented Mar 15, 2018 at 17:25
  • @Deepan The input is styled via "input:invalid{ border:2px solid red }" in a CSS file Commented Mar 15, 2018 at 17:25
  • 1
    Try to get the input element and get element.getCssValue("color")); Now if color is red you can mark it as invalid data Commented Mar 15, 2018 at 17:32
  • 1
    @InfernalRapture my pleasure :) Commented Mar 15, 2018 at 17:49

1 Answer 1

1

I was able to test for styling using the command

element.getCssValue("border-bottom-color");

Note: Testing for styles related to the border must specify a side, since styles that apply to all four sides is short hand that is broken out into styling for each side. border:blue will be erased and replaced by border-bottom-color:blue, border-top-color:blue, border-right-color:blue, and border-left-color:blue

Sign up to request clarification or add additional context in comments.

1 Comment

This answer based on comments left by @Deepan

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.