0

I have 6 selenium tests (TestNG) running on chrome and firefox (both up to date versions) which connect to Browser stack to run.

the problem is that 1 of the test fails intermittently on Chrome as the sendKeys method is entering the email twice after clearing the text field. (i have seen that field gets cleared successfully in the test run)

problem - value entered twice: test@test.comtest@test.com.

the tests run on gocd (like Jenkins) every morning. it only fails when run on gocd but when testing on my intellij these tests are always passing.

this is my code to clear and send the text

 private void editTextField(String textToInput, WebElement element) {
            element.clear();
            element.sendKeys(textToInput);
    }

        public void editPassengerDetails(String name, String lname, String email) {
        waitForPageCheckOutPageToLoad();

        openPassengerDetailsBox.click();

        editTextField(name, emailFirstName);

        editTextField(lname, emailLastName);

        editTextField(email, emailAddress);
}

test

checkoutPage.editPassengerDetails("Testfnames", "Testlname", "test@test.com");

can someone see anything wrong with this?

0

Make sure that before sending the text,filed is clearing properly. add assert before sendkeys to make sure that text field is empty

0

According to you statement, it looks like clear fails to clear field. Can you try to add following code into the automation to clear up field and test it with it?

static String getValueFromElement(WebElement locator) {
        return tryFindElement(locator).getAttribute("value")
    }

This method above will return you the what's written in the element.

static def retailPriceInputFieldCleaner(By locator) {
    WebElement inputFieldAsElement = tryFindElement(locator)
    getValueFromElement(inputFieldAsElement).length().times {
        inputFieldAsElement.sendKeys(Keys.BACK_SPACE)
    }
    this
}

And this one above will press backspace for each key written in the textbox. It's written in groovy but you can adapt it easyly to any language I guess.

And if it's possible please share the test case's itself since knowing how your method used would be useful for troubleshooting.

  • @Fenomenoq is this answer solves your problem? – TuRQuaS3 Nov 18 at 10:58
0

i raised a similar protractor issue on this , the issue seems like

  1. if you give a input say "one" to textbox 'A'
  2. then you clear text box 'A'
  3. and then sends input to textbox 'B'
  4. and then sends input say "two" again to textbox 'A', A will get the value onetwo

If you immediately use sendKeys after using clear() , everything works fine.

  1. if you give an input say "one" to textbox 'A'
  2. then you clear text box 'A'
  3. and then sends input say "two" again to textbox 'A', A will get the value two

In my case using the element in order fixed the issue

link to issue:

https://github.com/angular/protractor/issues/5370

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.