In the provided todo.cy.js test script, the 'can check off an item as completed' test fails when you try and choose 'Walk the dog' instead of 'Pay electric bill'.
I believe this might probably be exposing a bug in cypress where when there is a click event on an nth checkbox, it gets applied to the first checkbox on the same list.
cy.contains('Walk the dog')
.parent()
.find('input[type=checkbox]')
.check()
cy.contains('Walk the dog')
.parents('li')
.should('have.class', 'completed')
Related
For example if user dont fill this field and press "continue" button, this error message will pop up.
I wonder is there a way with Cypress that I check that error message was displayed?
Kind regards
You can make this assert : cy.get('input:invalid').should('have.length', 1)
See https://github.com/cypress-io/cypress-documentation/pull/1919/files how to assert the validation message
I know this is an older question but here is another solution.
cy.get(`[data-testid="XXXX"]`)
.invoke('prop', 'validationMessage')
.should((text: string) => {
expect(text).to.contain(YYYY);
});
Using the above code here is what happens:
You grab the input / textarea element using cy.get Note: it is recommended to use a data-testid or obtain the element by something less brittle so the test doesn't fail if the text changes etc.
Using the invoke method, you can check validationMessage against prop then then, obtain the inner text and use expect to check if it's valid. This is very handy if you use custom validation messages.
I have a website which has everything in an iFrame. My scripts are failing because cypress is not able to wait for loading bar as cypress does not support iframes as of now. I want to write a custom command which wait until attributes 'ng-reflect-loading' value is changed to false.
I have tried with below code but its not working and halts cypress runner. Reference Thread 136
cy.get('iframe').iframeLoaded().its('document').getInDocument('.main >ng-component > :nth-child(1)').then(function($loading) {
while( $loading.attr('ng-reflect-loading')!='false')
{
cy.log('waiting')
}
})
Can anyone please help on this.
I don't have any insight of how iFrames work. But is 'ng-reflect-loading' eventually hidden?
In that case this check should work:
cy.get('.ng-reflect-loading')
.should('not.exist')
If it remains existing but the value should change you could either check on the first value not existing:
cy.get('.ng-reflect-loading')
.should('not.contain.attr', 'attr_name', 'first value')
Or if the value changes, you could check for the second value to be available:
cy.get('.ng-reflect-loading')
.should('contain.attr', 'attr_name', 'second value')
I am getting below exception even when my element has already been clicked and i am navigated to next page.
Caused by: org.openqa.selenium.TimeoutException: Expected condition
failed: waiting for element to be clicked: [[ChromeDriver: chrome on
XP (56f040029c23126b0087ff1dfa82369e)] -> xpath:
//*[#id='login']/app-root/app-caf-login/div/div/div[2]/form/div[3]/div/div/button]
(tried for 10 second(s) with 500 milliseconds interval)
Verifying XPAth but since element is already clicked them not sure why error is coming.
Description: Click the Sign In Button
action: org.getopentest.selenium.Click
args:
locator: { xpath: "//*[#id='login']/app-root/app-caf-login/div/div/div[2]/form/div[3]/div/div/button" }
Description: Pause for 60 second
action: org.getopentest.selenium.ActionsPause
args:
durationMs: "60000"
Expected : no error should be there
As described in this answer make sure you don't use the sendEnter: true argument with any of the SendKeys actions. When you pass sendEnter: true , the action will "press" the enter key after sending the keys to the textbox element. So basically, in the test you showed, the first action will input the username and then press enter, thus trying to log in without a password, which will of course fail.
Also, you are using the ActionsPause keyword incorrectly (more info here). If you want to introduce a delay in your test, you can use the $delay() API, but you very rarely need to do this with OpenTest, since synchronization is built-in, meaning all test actions that perform some work on a UI element know how to wait for that element to be available before doing the work.
I want to check a page for an element before I start running the feature file for it (It's an element that periodically appears with an event so I only want to run the feature if its present).
The approach I wanted to use was a tagged before hook to see if the element was present and if it wasn't just don't run the feature but exit without 'failing' the step just exit with a message. I tried variants on the below but
1. If I don't have a rescue clause it obviously fails the scenario when the element isn't present
2. If I do have the rescue clause it handles it and passes moving onto the features which will then fail as the event isn't available.
Is there a way to halt running the feature file if the rescue clause is invoked without the 'fail'?
Before('#event') do
begin
find('.event').visible?
rescue Capybara::ElementNotFound
puts 'THE EVENT IS NOT ON'
end
end
You shouldn't be using find if you want to make a decision based on existence. Instead you should be using the predicate methods provided by Capybara (has_selector?, has_css?, has_xpath?, etc) so you don't have to rescue exceptions.
The other thing to know is the Cucumber skip_this_sceanrio method, which means you should end up with something like
Before('#event') do
# visit '/some_page' # May not be needed if you have another `Before` already visiting the needed page
skip_this_scenario('Skipping due to missing event') unless page.has_css?('.event')
end
How do I mark a cucumber scenario as pending so it doesn't get counted as a passed?
Scenario: Guest should not see edit link
# pending implementation
Shouldn't I be able to mark is as pending?
The problem with the #wip tag, I've found, is that it doesn't make your test suite yellow. It completely ignores the wip features, and you tend to forget they exist. This has bitten my team in the rear when scenarios are tagged as #wip and then forgotten. I wish there was a better solution. The best I have is adding this custom step:
Given /^PENDING/ do
pending
end
Rather than mark a real feature as pending, I can put this into the lineup with a message, like so:
Given PENDING: we need client input
Then it shows up like this:
(::) pending steps (::)
features/example.feature:15:in `Given PENDING: we need client input'
Pending halts the chain of tests, but it does NOT prevent cucumber from nagging about any undefined steps that follow in that same scenario. Also, ideally failing and pending features would tell you the name of the scenario that failed, but they don't.
Okay figured this one out.
The Scenarios steps are marked as pending if it's not found in any of the steps files.
Scenario: New product form should have some special field
Given joe is logged in as an user
When on the new exercise page
Then the select field should have some special field
It's even nice enough to stub out the pending step.
When /^on the new exercise page$/ do
pending # express the regexp above with the code you wish you had
end
Another possibility is the #wip tag (work in progress). Scenarios tagged #wip will not be run by default, but just when you explicitly request them.
#wip
Scenario: New product form should have some special field
Given I still work on this feature
This way you can exclude some scenarios from the automated build, so that it doesn't break while you are working on the feature.
In addition to averell's answer, you can exclude scenario tags when running cucumber.
If #todo and #wip are tags you want to use for scenarios that are work in process or just mark pending scenarios, run your features like:
cucumber --tags ~#todo --tags ~#wip
If you're using Guard do something like this:
guard 'cucumber', :notification => true, :all_on_start => true,
:cmd => "bundle exec cucumber",
:cli => "--tags ~#todo --tags ~#wip" do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || 'features'
end
end