i want to trigger a button after 150 seconds so i written a logic like this.
///<reference types="cypress"/>
describe("home test",function (){
it('home',function (){
cy.visit('http://localhost/SNL.Services.Application.Common.Service/v1/client?ccaTopNav=1&auth=inherit#news/home');
cy.get('.header-button > .btn-default',{timeout:180000}).click({force: true});
cy.intercept('POST', 'https://platform.midevcld.spglobal.com/apisvcs/logging-service/v1/AI/LogClientTelemetry?clientdate=1650881902895', {
statusCode: 204
}).as('lastXhr')
cy.wait('#lastXhr')
cy.contains('.header-button', 'REMIND ME LATER')
})
})
my actual scenario: when i opened the localhost its takes time(65s) to open the popup so that i added a functionality to click the button after 150 seconds.
in the (65 seconds) meantime it making some api call that is the delay for the 55s.
but after 55 th second it takes 5-10s to open the popup. that's where my Remind me button is located. but when the 55seconds completed its showing the few html elements(after that take 10 sec to show popup) in that it immedietly checking the selector so that my button click is not working as expected.
can anyone guide me how to make the click event on my scenario.
Try changing the order, intercept should always go at the top.
cy.intercept('POST', 'https://platform.midevcld.spglobal.com/apisvcs/logging-service/v1/AI/LogClientTelemetry?clientdate=1650881902895',
{statusCode: 204}
).as('lastXhr')
cy.visit('http://localhost/SNL.Services.Application.Common.Service/v1/client?ccaTopNav=1&auth=inherit#news/home');
cy.get('.header-button > .btn-default',{timeout:180000}).click({force: true});
cy.wait('#lastXhr')
cy.contains('.header-button', 'REMIND ME LATER')
Related
screenshot of html code for the error toast popupI am trying to get the element of popup (or) toast-container and asserting the text, but I am getting an error that element never found. Please someone help?
describe('Wholesoft Login Page', function(){
it('Check Login popup', function(){
cy.visit('https://https://platform.wholesoftmarket.com/login')
cy.get('#email').type('kj#gmail.com')
cy.get('#password').type('hello')
cy.get('button.btn.active').click()
cy.get('div').within(($div)=>{
cy.get('div.overlay-container').should('have.text','no record found')
})
})
})
You need to set a bigger timeout for the element, waiting to be present in the DOM:
cy.get('div[aria-label="Error"]', {timeout: 10000}).should('have.text','no record found')
// maybe you can use the class selector on that div (div.toast-title.ng-star-inserted)
// default timeout is 6000
// increase it until it is caught by Cypress
You need to wait till the toast or pop-up element is visible to access it for further steps.
Please make sure element selector is right.
following cmd
cy.get('div.overlay-container').should('be.visible').should('have.text','no record found')
I'm using this in my end to end test:
//Ignore fit for now, I'm trying to resolve single issue, and I have 30ish tests in the file
fit('Advanced search for ID should work', async function() {
await browser.navigate().refresh();
//Positioning on the right tab where serach works
await attachmentHomepage.clickBtnRighTab();
//Waiting for advanced search button to load on that tab
await browser.wait(EC.elementToBeClickable(attachmentHomepage.btnAdvancedSearchToggle), 3000, 'waiting for button to be clickable');
//Clicking it and opening hamburger like menu on the left side of the screen (which, if I click anywhere looses the focus)
await attachmentHomepage.clickBtnAdvancedSearchToggle();
await browser.wait(EC.elementToBeClickable(attachmentHomepage.inputAttachmentIDAdvancedSearch), 5000, 'waiting field to be clickable');
//Waiting for the field in the menu (Pseudo element) to become available
await attachmentHomepage.setAttachmentIDInAdvancedSearch('1333');
await browser.wait(EC.elementToBeClickable(attachmentHomepage.btnAdvancedSearchApply), 5000, 'waiting button to be clickable');
//--->>> Waiting for apply button that is in the same advanced search hamburger menu <<<----
await attachmentHomepage.clickBtnApply();
await browser.wait(EC.elementToBeClickable(attachmentHomepage.tblMainDataTable), 5000, 'waiting for main data table to be "clickable"');
await browser.sleep(1000);
expect(await attachmentHomepage.returnFirstResult()).toEqual('1333');
});
My problem here is - this works, but not every time.
Every now and then I have a feeling that browser.wait for btnAdvancedSearchApply simply does not work.
Every time I run test, it opens the hamburger thing, it fills in the searched ID, and then it seems like it clicks somewhere on the screen instead of waiting for the button, and hamburger menu closes, and test fails.
Not sure how to make it wait every single time and 100% works.
Suggestions?
I am able to run the test code and i am able to submit the form. I need the url of next page when submit button is click. I need to get url of next page when submit button is clicked. But i am getting curenturl of first page.
My code:
describe('Pmts app 5.0',function(){
var LoginPage = require("./LoginPO");
it('login test', function(){
LoginPage.setUserName('xyz#test.com');
LoginPage.setPassWord('test');
LoginPage.clickButton();
expect(browser.getCurrentUrl()).toEqual('https://localhost:1234/#/timesheet');
});
});
After submit button is clicked browser get closed immediately and it is not waiting for next page to load. Once the button is submitted it should wait until next page load and I need url of next page...
Put it in the following way:
LoginPage.clickButton().then(function(){ expect(browser.getCurrentUrl()).toEqual('https://localhost:1234/#/timesheet');
})
or you can put a explicit hard sleep:
browser.sleep(time in ms)
or you can put a browser.wait() to wait for certain element that appears on the next page:
browser.wait(function(){
return elem.isPresent()
},time in ms).then(function(){
expect(browser.getCurrentUrl())
.toEqual('https://localhost:1234/#/timesheet');
})
Please refrain from using browser.sleep(number), instead go for browser.waitForAngular() if your application is Angular.js based.
Using hard coded dependency is never a good idea.
I have noticed, that the time Protractor needs to load the whole page varies. Therefore, either use browser.waitForAngular() or set a high number in browser.sleep()
Try this :
describe('Pmts app 5.0',function(){
ptor = protractor.getInstance();
var LoginPage = require("./LoginPO");
it('login test', function(){
LoginPage.setUserName('xyz#test.com');
LoginPage.setPassWord('test');
LoginPage.clickButton();
ptor.sleep(1000);
expect(browser.getCurrentUrl()).toEqual('https://localhost:1234/#/timesheet');
});
});
I have a problem with the Dojo Dijit Dialog .hide() method during the animation sequence. I am using Dojo 1.7 with Tundra theme. I have a cancel button in my dialog that closes the dialog.
var global_welcome = new Dialog({
id: 'global_welcome',
style: "width: 750px",
draggable: false,
content: '<button type="button" id="global_welcomeCancel"> Cancel </button>',
onShow : function () {
on(dojo.byId('global_welcomeCancel'), "click", function (evt) {
dojo.stopEvent(evt);
global_welcome.hide();
});
});
}
});
This produces the following error on Firebug:
exception in animation handler for: onEnd fx.js (line 152)
TypeError: this._fadeOutDeferred is undefined
this._fadeOutDeferred.callback(true);
Previous answers to this error but with destroyRecursive instead of hide suggests it has to do with the dialog being destroyed before the animation finishes. I tried using dojo.hitch() and setTimeOut but that didn't seem to work. Also what is puzzling is that the first time I open this dialog using global_welcome.show() (called by another button), and press the cancel button, it works without error. The second time and afterwards, it produces the above error message. Additionally, the default close button for dojo dialogs on the top right corner never causes this error. Perhaps I could just have onShow call the methods that the close button calls?
Can someone help me out please? Thanks in advance!
The problem is in your onShow method. You wire up to the click event to hide, but never disconnect it. When you open the dialog the again, you wire the click method to hide the dialog again. The result is that hide will be called twice when you try to close the dialog for the second time. The error gets thrown with the second call to hide because the animations have already been destroyed.
Try this:
var signal = on(dojo.byId('global_welcomeCancel'), "click", function (evt) {
dojo.stopEvent(evt);
signal.remove();
global_welcome.hide();
});
Using the event click with live function leads to strange behavior when using Firefox*.
With live in Firefox, click is triggered when right-clicking also! The same does not happen in Internet Explorer 7 neither in Google Chrome.
Example:
Without live, go to demo and try right clicking
the paragraphs. A dialog menu should
appear.
With live, go to demo and try right
clicking "Click me!". Now both dialog
menu and "Another paragraph" appear.
*tested with firefox 3.5.3
As far as I know, that is a known issue (bug?). You can easily work around it by testing which button was clicked as follows:
$('a.foo').live("click", function(e) {
if (e.button == 0) { // 0 = left, 1 = middle, 2 = right
//left button was clicked
} else {
//other button was clicked (do nothing?)
//return false or e.preventDefault()
}
});
you might prefer using a switch depending on your specific requirements, but generally you would probably just want to do nothing (or or simply return) if any button other than the left button is clicked, as above:
$('a.foo').live("click", function(e) {
switch(e.button) {
case 0 : alert('Left button was clicked');break;
default: return false;
}
});
I think it's a known "bug", you could potentially query the event object after attaching the click handler ( which gets attached to the document ) and see if its a right click, otherwise manually attach the click handler after you manipulate the DOM.
After looking it up, e.button is the property you want to query:
.live('click', function(e){
if ( e.button == 2 ) return false; // exit if right clicking
// normal action
});
See my answer here: if you don't mind changing the jQuery source a bit, adding a single line in the liveHandler() works around the problem entirely.