How to add a wait in the feature file for the karate framework? - user-interface

And click("//button\[text()=' Next '\]")
And match driver.title == 'ONE'
And click("//\*\[#id='BusinessUnits'\]/li\[2\]/a")
I want to add waiting time between 2nd and 3rd line. How can I add that ?
I have tried adding sleep that doesnt work

Use delay() refer the docs: https://github.com/karatelabs/karate/tree/master/karate-core#delay
Note that you normally never need to use that if you write tests the right way.

Related

How to address Cypress (cy.type() can only be called on a single element.) error?

I have three input fields:
cy.get(':nth-child(1) > .input-module_input__3wsvS').should('be.visible').type(foo)
cy.get(':nth-child(2) > .input-module_input__3wsvS').should('be.visible').type(bar)
cy.get(':nth-child(3) > .input-module_input__3wsvS').should('be.visible').type(foo-bar)
How to I get my test to pass? I am using css modules in react. ID-Tags don't seem to work, so any other suggestions?
.first() is ok to identify the 1st, but how would I address the 2nd and 3rd input?
Be careful using the "hash" the originates from frontend websites who use css-modules as any change to the underlying css will change its value and therefore break the tests.
Similarly the more complicated a selector is the more surface area there is for change in the structure of the document to break the test.
.eq() is how you select children by index (0 based) you can find the documentation here:
https://docs.cypress.io/api/commands/eq
For projects using css modules i'd suggest using the "starts with" selector
cy.get(`[class^='${cls}']`))
// or add the following command for "partial class" to make writing it easier
Cypress.Commands.add('pclass', (cls) => cy.get(`[class^='${cls}']`));
usage in your example:
cy.get(`[class^='input-module_input']`).eq(1) // (for second child)
// or (After you've added the command)
cy.pclass("input-module_input").eq(1); // (for second child that mathes)
Using .eq() might give you better results
cy.get('.input-module_input__3wsvS').eq(0).should('be.visible').type('foo')
cy.get('.input-module_input__3wsvS').eq(1).should('be.visible').type('bar')

Logging and asserting the number of previously-unknown DOM elements

I'ts my first tme using Cypress and I almost finalized my first test. But to do so I need to assert against a unknown number. Let me explain:
When the test starts, a random number of elements is generated and I shouldn't have control on such a number (is a requirement). So, I'm trying to get such number in this way:
var previousElems = cy.get('.list-group-item').its('length');
I'm not really sure if I'm getting the right data, since I can not log it (the "cypress console" shows me "[Object]" when I print it). But let's say such line returns (5) to exemplify.
During the test, I simulate a user creating extra elements (2) and removing an (1) element. Let's say the user just creates one single extra element.
So, at the end os the test, I need to check if the number of eements with the same class are equals to (5+2-1) = (6) elements. I'm doing it in this way:
cy.get('.list-group-item').its('length').should('eq', (previousTasks + 1));
But I get the following message:
CypressError: Timed out retrying: expected 10 to equal '[object Object]1'
So, how can I log and assert this?
Thanks in advance,
PD: I also tryed:
var previousTasks = (Cypress.$("ul").children)? Cypress.$("ul").children.length : 0;
But it always returns a fixed number (2), even if I put a wait before to make sure all the items are fully loaded.
I also tryed the same with childNodes but it always return 0.
Your problem stems from the fact that Cypress test code is run all at once before the test starts. Commands are queued to be run later, and so storing variables as in your example will not work. This is why you keep getting objects instead of numbers; the object you're getting is called a chainer, and is used to allow you to chain commands off other commands, like so: cy.get('#someSelector').should('...');
Cypress has a way to get around this though; if you need to operate on some data directly, you can provide a lambda function using .then() that will be run in order with the rest of your commands. Here's a basic example that should work in your scenario:
cy.get('.list-group-item').its('length').then(previousCount => {
// Add two elements and remove one...
cy.get('.list-group-item').its('.length').should('eq', previousCount + 1);
});
If you haven't already, I strongly suggest reading the fantastic introduction to Cypress in the docs. This page on variables and aliases should also be useful in this case.

Ruby Selenium - How to check if text is present only once

I am working on a application that reports status updates on certain services. I am using Ruby Selenium for testing the application.
For the same purpose I wana test some updates that are just plain text - these updates should appear exactly once in the page. Thus, how can I test if a web page has some text only once ?
I am looking for something like
assertTextPresentOnlyOnce ??
I believe you are looking something like this..:
!20.times { break if (selenium.is_visible(driver.find_element(:id, 'loginid'))
rescue false ); sleep 1}
.
.
[rest of the code you want to execute]
.
.
This will cover you and for page time-out as well if the element you want is not present yet. As soon as selenium finds the element you want the loop will break and the code below will be executed.

How do I use Watir::Waiter::wait_until to force Firefox to wait?

I have some buttons that get disabled when adding a user.
What I need to be able to do is have firewatir wait_until something is present.
I am trying to use this right now:
count = 10
while count > 0
browser.button(:name, "_eventId_addEmployee").click
Watir::Wait.wait_until_present {text.exist? newHireUsername}
end
count -= 1
end
For some reason I can't get the wait_until method to work correctly.
Thanks in advance!
I usually do something like this,
browser.element_type(:id, "xxx").wait_until_present
Instead of using the wait_until_present option I used an until loop to wait for text to appear.
This by-passed attempting to use it so it does not qualify as an answer for my original question but want it here for others.

JMeter "if controller" with parameters?

I was reading the JMeter documentation and came across this info box about "If Controllers":
No variables are made available to the script when the condition is interpreted as Javascript. If you need access to such variables, then select "Interpret Condition as Variable Expression?" and use a __javaScript() function call. You can then use the objects "vars", "log", "ctx" etc. in the script.
I don't quite follow this. Does this mean if I want access to a "User Defined Parameter" then I can access it only by writing some JavaScript? The example that follows this box then refers to "${COUNT}"
Could someone clarify the usage of the If Controller, maybe with an example or two?
All these answers are wrong! You need to put the variable reference in quotes, like so:
"${my_variable}"=="foo"
You can simply use something like
${my_variable}=='1'
Sometimes JMeter documentation can be confusing :)
Edit 27 september 2017:
The answer here works but has a very bad performance impact when number of threads exceeds 40.
See below for correct and most performing answer:
https://stackoverflow.com/a/46976447/460802
See:
https://bz.apache.org/bugzilla/show_bug.cgi?id=61675
UNCHECK the CHECKBOX
"Interpret condition as variable expression"
I wasted a couple of hours without unchecking this checkbox. It worked with and without semicolon(;) at the end of the statement. Make sure that you have set the User-Defined Variables before calling the if controller.
All the following variations worked for me in Jakarta Jmeter 1.5
${__javaScript("${HOMEPAGE}"=="Y")}
${__javaScript("${HOMEPAGE}"=="Y")};
"${HOMEPAGE}"=="Y"
"${HOMEPAGE}"=="Y";
If Controller will internally use javascript to evaluate the condition but this can have a performance penalty.
A better option (default one starting from JMeter 4, see https://bz.apache.org/bugzilla/show_bug.cgi?id=61675) is to check "Interpret Condition as Variable Expression?", then in the condition field you have 2 options:
Option 1 : Use a variable that contains true or false. For example If you want to test if last sample was successful, you can use
${JMeterThread.last_sample_ok}
or any variable you want that contains true/false
${myVar}
Option 2 : Use a function (${__jexl3()} is advised) to evaluate an expression that must return true or false.
For example if COUNT is equal to 1:
${__jexl3("${COUNT}"== "1",)}
OR
${__jexl3(${COUNT}== 1,)}
Starting with 4.0, if you don't use the "Interpret Condition as Variable Expression?", a warning in RED will be displayed:
If you'd like to learn more about JMeter and performance testing this book can help you.
God bless the http://habrahabr.ru
Have tried until found these.
Using the quotes was my solution.
As Gerrie said you need to check your variable
${my_var} == 'value'
But be careful with the 'User Defined Variables'
Note that all the UDV elements in a
test plan - no matter where they are -
are processed at the start.
That basically means that you cannot define 'User Defined Variables' inside an 'If Controller'. Take a look to the 'BeanShell' instead.
Replace:
${my_variable}=='1'
with
"${my_variable}" == "1"
if it's string value pass as below and its performance effective
${__groovy("${key}"=="value")}
I have used ${code_g1}== 200 in condition and it worked for me.

Resources