Timeout error for element already clicked - opentest

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.

Related

Wait until element has disappeared in Cypress

please, tell me what methods to use to wait for a loading screen element to disappear? PS. I'm not using an API request.
I tried to use two methods, but it doesn't work properly:
1. cy.get('#loading', { timeout: 30000 }).should('not.be.visible');
I get the error: -- Timed out retrying after 30000ms: Expected to find element: #loading, but never found it.
2. Used plugin (cypress-wait-until) like so cy.waitUntil(() => {document.querySelector('#loading') === null};
This approach doesn't find the element at all.
If you are trying to retrieve an element that is not in the DOM, use not.exist instead:
cy.get('#loading').should('not.exist');
In cases where you do need to wait, you can try using cy.wait:
An example use case for this might be if Cypress has to route to your page first and you want to ensure the page loads before you start testing:
cy.wait(200);

How to validate Browser Error's message with cypress

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.

Cypress - How to Wait for an attribute value to be false in Cypress

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')

timeout Exception even when element is already clicked

I am trying to click one button Sign In but even after button is clicked I am getting timeout exception.
I have verified the code and verified that I am using right locator.
description: CAP Demo
Navigate to the GitHub website, find the React repo using the
search functionality and go to the repo's homepage
actors:
- actor: WEB
segments:
- segment: 1
actions:
- description: Navigate to the GitHub homepage
action: org.getopentest.selenium.NavigateTo
args:
url: http://192.168.200.98:8780/CAFPortal/#/login
- description: Enter Login id
action: org.getopentest.selenium.SendKeys
args:
locator: {xpath: "//*[#id='login']/app-root/app-caf-login/div/div/div[2]/form/div[1]/input"}
text: ksood
sendEnter: true
- description: Enter password
action: org.getopentest.selenium.SendKeys
args:
locator: {xpath: "//*[#id='login']/app-root/app-caf-login/div/div/div[2]/form/div[2]/input"}
text: Acs#2018
sendEnter: true
- description: Pause for 60 second
action: org.getopentest.selenium.ActionsPause
args:
durationMs: 60000
- description: Display a greeting dialog box in the browser
action: org.getopentest.selenium.ExecuteScript
args:
script:
var message = "Hello World!";
alert(message);
- description: Click on sign in
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"}
Just want the last testcase to pass
You don't need 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.
The other problem is that 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.

How to fix "unexpected alert open: {Alert text : } " error

I have a project in ruby with AngularJS and I'm currently converting tests over to Headless chrome from Phantomjs, and I keep getting an error:
Selenium::WebDriver::Error::UnhandledAlertError:
unexpected alert open: {Alert text : }
This happens throughout multiple test files..
I have tried adding
"accept_alert {} " before a command :
#from
find('.sp-advanced-configuration').click
#to
accept_alert{ find('.sp-advanced-configuration').click }
but receive
Failure/Error: accept_alert{ ... }
Capybara::ModalNotFound:
Unable to find modal dialog
as well as
Selenium::WebDriver::Error::UnhandledAlertError:
unexpected alert open: {Alert text : }
Not sure what else to try
/*********** *********/
After looking into this further, It seems the issue occurs whenever there are unsaved changes left on the test before moving onto the next test.
Is there a way where you can accept this for every test without having to add
after do
execute_script('window.onbeforeunload = undefined')
end
in every test file?
The reason you're seeing this is that Poltergesit/PhantomJS used to automatically accept unexpected system modals. The selenium driver doesn't do that because your test should actively either accept or decline it. Is find('.sp-advanced-configuration').click the action that opens the alert box? From the errors you're getting I would guess not. The block accept_alert receives needs to be the block that actually triggers the opening of the system modal. This means your code probably needs to be
accept_alert { # action that triggers the alert }
find('.sp-advanced-configuration').click

Resources