Karate testing UI : what is syntax entering random value in text field - karate

I am trying to enter a random string in text box using the input(“X-path”,’#(name)’). Script is failing with invalid syntax .
Can anyone help me with the correct syntax

Here is the working sample script created for POC
Feature: create order
Background
def now=function(){return java.lang.System.currentTimeMills()}
*def ordername='order'+now()
Scenario: Create random order
Given call read('login.feature')
Given driver 'url to navigate to another page'
And click('#selector')
And input("x-path",ordername)

I think you missed the fact that variables can be used "as is" in JS functions.
* def name = 'foo'
* input('/some/path', name)
The '#(name)' syntax is only for JSON: https://github.com/karatelabs/karate#rules-for-embedded-expressions

Related

Karate UI: Entering input using variable values

KarateUI question
I'm trying to enter values in a text field using a variable. Example:
* def foo = bar
* waitFor("input[aria-label='Search Input']").input('<foo>' + Key.ENTER)
This results in value being entered in the Search Input field.
I have been using the '<[something]>' successfully on a number of other places, not sure why it's not working in the above example.
I have tried a number of other approaches following the documentation without much luck.
Karate "variables" can be mixed into plain JavaScript. So try this:
* def foo = 'bar'
* waitFor("input[aria-label='Search Input']").input(foo + Key.ENTER)
That's right, no angle-brackets required.
Also see: https://github.com/karatelabs/karate#scenario-outline-enhancements
If still stuck, follow this process please: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

Failed to select options in drop-down using select class in karate bdd [duplicate]

So i'm pretty sure that I'm doing something wrong but here it goes.
I'm trying to implement Karate UI to press a drop down menu and then select an element from that drop down.
Scenario: go to manual entitlement
Given driver 'url'
* waitForText('body', 'Commuted value')
When waitFor('#event-dropdown').click()
And select('select[id=event-dropdown]', 'Disability')
And def checkBox = waitUntil('#chkbox_pen_label0')
Then match text(checkBox) == 'Some text'
The HTML looks as follows
HTML
Would appreciate any help I can get.
I think this should work, refer the docs: https://github.com/intuit/karate/tree/master/karate-core#select
And select('#event-dropdown', '{}Disability')

Can we give null values or empty strings in the input fields for UI Automation?

I am new to karate Automation, testing simple login window where need is to validate the blank fields. When I am inserting empty string " " in input function it's failing the step. How we can achieve this?
* input("//input[#name='password']", " ")
I want to validate the error message which appears when user leaves password field as blank.
Thanks in advance!
The below works fine for me. So maybe you are missing something. A lot depends on the page, maybe there is some JS validation.
* driver 'https://github.com/login'
* input('#login_field', ' ')
* input('#password', ' ')
* submit().click("input[name=commit]")
* match html('#js-flash-container') contains 'Incorrect username or password.'
If still stuck, please follow this process: https://github.com/intuit/karate/tree/develop/examples/ui-test

TestCafe does not write in text input field

I'm using TestCafe for test automation of a web application based on the Wicket framework. I try to type text into a text input field ... well, actually it is a dropdown list, where a text input field appears, so that the user can search for certain codes. The HTML fragment is as follows:
HTML fragment
And here is the corresponding screenshot (text field above "001"):
Text input field with dropdown
The user can type some characters and the list below is automatically filtered (I did this manually):
Text input field with some text
My TestCafe test tries this:
.click( productcodeList )
.expect( productcodeInputField.visible ).ok()
.click( productcodeInputField )
.typeText( productcodeInputField, 'ABW' )
i.e.
Click on the drop down list.
Assume that the text input field is now visible (works fine).
Click on the text input field (this should not be necessary, since typeText() is supposed to do this anyway).
Type the text "ABW" into the text input field ==> This does not work.
I'm sure that my Selector works, since the assertion (expect) is successful and when I debug the test run after the second click (on the text input field), I see the following:
TestCafe screenshot
I.e. the cursor is directly on the text field, but somehow TestCafe cannot write the text into the field.
Some additional information: The Selector for the input field is created as follows:
productcodeInputField = Selector('span').withAttribute('class', /select2-dropdown.*/ ).child('span').withAttribute('class', /select2-search.*/ ).child('input').withAttribute('class', 'select2-search__field' );
More information: I'm using the same logic on the same page:
kurzbezeichnungField = Selector('input').withAttribute('name', /.*aeAbbreviation.*/);
...
await t.click( kurzbezeichnungField )
.typeText( kurzbezeichnungField, 'xxxWWW' )
and this works fine.
Node.js version: v10.16.3
Testcafe version: 1.5.0
This issue looks like a bug. However, I cannot say it precisely without an example that demonstrates the problem.
My team would really appreciate it if you share your project or sample to demonstrate the issue.
Please create a separate issue in the TestCafe github repository using the following template and provide as much additional information as possible.

Can't pass a Test Execution result to a variable in Robo Framework

I am posting the results of automated tests to an offline forum. It would be nice to include PASS/FAIL in the forum post title but I'm having some difficulties retrieving the ${TEST STATUS} value - (obviously a hard-coded value works fine) .
I've defined the following in common-variables.robot as:
${FORUM_TEST_RESULT}....${TEST STATUS}
then on publish-results.robot
Input Text....//*[#id="title"]....${FORUM_TEST_RESULT}
The error I get is: variable ${FORUM_TEST_RESULT} not found
I can see here: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#listener-interface that ${TEST STATUS} can only be used as part of Teardown.
I'm not sure how to collect the value of ${TEST STATUS} in the context of my RF script.
e.g the very last thing my script does is post to a forum:
Input Text....//*[#id="title"]....${FORUM_TEST_RESULT}
but before that I obviously need to populate ${FORUM_TEST_RESULT} with the value of ${TEST STATUS) which you can only get on Teardown? Hope this makes sense.
Input Text is a keyword of Selenium2Library that types the given text into the text field of a web page. You need to start a browser session first and open the right page an then possibly wait for the element to become visible, for example like this:
Open Browser [URL of your site]
Wait Until Element Is Visible //*[#id="title"]
Input Text //*[#id="title"] ${FORUM_TEST_RESULT}
If you want to retrieve a text from a page (as your coment suggests) then you need to use the keyword Get Text which returns the text of the element identified by locator.
Get Text locator