question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Input() with Key.ENTER and click() don't work as expected

See original GitHub issue

I’m using the standalone version. To run this code use 0.9.6-RC3 because of this reported bug.

I have two questions highlighted below, as comments in the code.

Feature: Amazon UI automation

  Background:
    * def baseUrl = 'https://www.amazon.com/'

  Scenario: Search for item
    Given driver baseUrl
    And def searchTerm = "Explore It"
    And def searchTermEncoded = "Explore+It"
    
    # Q1: Key.ENTER should trigger the search but nothing happens, like the key isn't sent. Why?
    # When input("#twotabsearchtextbox", [searchTerm, Key.ENTER])
    
    # So I have to click the search button manually
    When input("#twotabsearchtextbox", searchTerm)
    And click("#nav-search-submit-text")
    
    # Q2: At this moment, I should be seeing the search results, but I'm still in the homepage. Why?
    Then match driver.url contains "s?k=" + searchTermEncoded
    And locate("div.s-result-list").exists                   
    And locate("{span}Reduce Risk and Increase Confidence").exists

I tried using the same actions and selectors on Cypress and the flow works. Am I doing something wrong in Karate? Why can’t I reach the search results page?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ptrthomascommented, Jun 27, 2020

for those coming across this thread in the future - after more investigation - the ENTER key was indeed being handled wrong in chrome native, which is now fixed in #1192

1reaction
dialexcommented, Jun 14, 2020

haha, I have an open mind 😉 Cypress had its problems too in the first years

Here’s what I tried:

  • The test still failed with this change Then waitForUrl('s?k=' + searchTermEncoded)
    • If we are waiting for the url to change and it never happens, that’s because it’s not being clicked. So the issue must be the click.
  • The test still failed with this change And mouse("#nav-search-submit-text").click()
    • So that click() and mouse().click() are diff syntaxes for the same behaviour This alone is not enough to fix the test
  • Maybe I need to explicitly wait for the click to happen.
    • So I added And waitFor('#nav-search-submit-text').click() after the mouse click. This worked… 🎉 sometimes 😢

My results:

  • ⚠️ I only got the test passing when I used mouse().click() together with waitFor().click(). Please tell me I don’t have to wait for every UI interaction 😱
    • Is this a requirement? I hope not, even Selenium is capable of waiting for steps and waiting for load pages, but the truth is, it only “worked” when I did this.
    • And if it’s not a requirement, then why do I get this behaviour? Is it specific to the standalone version? It’s a really simple test, executed in isolation.
  • [5 out of 10 runs] ⚠️ I noticed that “sometimes” Karate would not input the whole search term (e.g. instead of “Explore It” just “Explore” or “Explore I”.
    • It looks like the mouse().click() step doesn’t wait for the previous step to finish. Karate should run all steps of a given test sequentially right? Or are they executed in parallel? (Selenium runs steps sequentially. Cypress runs commands in parallel, but still, each step executes after the previous)
  • [1 out of 10 runs] ⚠️ The waitFor().click() is not reliable either. One time the click and page reload was so fast, that when the waitFor executed, the page had reloaded and the button was no longer there: TypeError: Cannot read property 'click' of null

For reference, this is the test code that sometimes works:

Scenario: Search for item
    Given driver baseUrl
    And def searchTerm = "Explore It"
    And def searchTermEncoded = "Explore+It"
    
    # This one-liner should work, but doesn't
    # When input("#twotabsearchtextbox", [searchTerm, Key.ENTER])
    When input("#twotabsearchtextbox", searchTerm)
    
    # This should work, but doesn't
    # And click("#nav-search-submit-text")
    And mouse("#nav-search-submit-text").click()
    
    # This should not be necessary, but it is
    And waitFor('#nav-search-submit-text').click()
    
    Then match driver.url contains "s?k=" + searchTermEncoded
    And locate("div.s-result-list").exists
    And locate("{span}Explore It!: Reduce Risk and Increase Confidence with Exploratory Testing").exists
Read more comments on GitHub >

github_iconTop Results From Across the Web

Pressing Enter key on input field does not work as expected
For some reason when I press the Enter key while on the input field it doesn't submit the form. Instead the focus is...
Read more >
Input() with Key.ENTER and click() don't work as expected
I'm using the standalone version. To run this code use 0.9.6-RC3 because of this reported bug. I have two questions highlighted below, ...
Read more >
The Enter Key should Submit Forms, Stop Suppressing it
When enter is clicked in the number input, the keypress event handler determines which submit button is appropriate and clicks it. While this ......
Read more >
On Change action - waiting for the enter key - OutSystems
Edward I have used the Run Javascript in the on change action and it does not work. Eduardo is right. But the problem...
Read more >
When a Click is Not Just a Click | CSS-Tricks
The click event is usually tied to a pointer device, typically the mouse, and yet here the Space or Enter key are triggering...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found