dimanche 21 décembre 2014

How to write a string in textfield which contains underscore in it using TestFX?

I am writing a simple login form in JavaFX for which I am writing a test program in TestFX. My TestFX script automatically types the credentials in the textfields and clicks the login button and it works fine further.


But when I want the script to type credentials which contain underscore, it doesn't type the underscore and types until the underscore comes. I have used backslash before underscore but it didn't help me.


Below is a screenshot of my login page.


enter image description here


Below is my test script which works fine when I give string without an underscore.



@Test
public void invalidCredentialsShouldNotLogin()
{
controller.click("#username").type("invalid");
controller.click("#password").type("invalid");
controller.click("#button");

verifyThat("#welcome", hasText("Login failed"));
}


And this is the script which tries to type a string which contains underscore in it and does not work as intended, and gives exception as invalid key code.



@Test
public void invalidCredentialsShouldNotLogin()
{
controller.click("#username").type("user_name");
controller.click("#password").type("invalid");
controller.click("#button");

verifyThat("#welcome", hasText("Login failed"));
}


This is the output of the above code.


enter image description here


The same thing happens when I use colon in place of underscore. Please help me fix this. If you require any more information, please tell me. Thanks


Aucun commentaire:

Enregistrer un commentaire