'Issues entering text into input field
I get the following error when entering text into an input field:
When input('input[name=q]', {"query":"null' AND 1509=BENCHMARK(5000000,MD5(0x55465268))-- UzJi","handshake":"d0tTest","filters":[]})
js failed:
>>>>
01: input('input[name=q]', {"query":"null' AND 1509=BENCHMARK(5000000,MD5(0x55465268))-- UzJi","handshake":"d0tTest","filters":[]})
<<<<
org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (input) on com.intuit.karate.driver.chrome.Chrome@2c1f8dbd failed due to: no applicable overload found (overloads: [Method[public com.intuit.karate.driver.Element com.intuit.karate.driver.DevToolsDriver.input(java.lang.String,java.lang.String)], Method[public default com.intuit.karate.driver.Element com.intuit.karate.driver.Driver.input(java.lang.String,java.lang.String[])], Method[public default com.intuit.karate.driver.Element
Solution 1:[1]
It looks like what you sent as the argument is not a string and was JSON in your case.
For example:
* def data = {"foo":"bar"}
* input('#inputId', data)
This will fail, because Karate treats data here as a JSON / object data-type.
The solution is to do this (see the single-quotes):
* def data = '{"foo":"bar"}'
* input('#inputId', data)
EDIT: as an alternative, this may work (brute force JS):
* def data = '{"foo":"bar"}'
* script('#inputId', "_.value='" + data + "'")
Also refer the documentation for other ways to do type conversions: https://github.com/karatelabs/karate#type-conversion
For completeness and for me to refer people to in the future, I'm showing how you can create an end-to-end example locally to test / simulate this case.
Here is the HTML:
<!doctype html>
<html>
<head>
<script>
var karate = {};
karate.get = function(id) { return document.getElementById(id) };
karate.setHtml = function(id, value) { this.get(id).innerHTML = value };
</script>
</head>
<body>
<input id="inputId"/>
<button id="buttonId" onclick="karate.setHtml('containerId', karate.get('inputId').value)">Submit</button>
<div id="containerId"></div>
</body>
</html>
And here is the test:
* driver serverUrl + '/myhtml'
* def data = '{"foo":"bar"}'
* input('#inputId', data)
* click('#buttonId')
* waitForText('#containerId', '{"foo":"bar"}')
And please note that we have made it super-easy to write your own simulations using this sample project: https://github.com/karatelabs/karate/tree/develop/examples/ui-test
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
