Cypress loses focus, and fails the test
Always fails in command line interface, flaky in UI mode
Unsuccessful run
Successful run
it("Copy and paste tasks", () => {
// Get the row count
cy.get("rowClass").then(rows => {
// Copy the last row
cy.get("rowClass").eq(-1).find("class to select whole row").click();
cy.get("body").type("{ctrl+c}");
cy.get("rowClass").eq(-1).should("have.class", "cut-copy-animation");
// Select the first row and paste
cy.get("rowClass").eq(0).find("class to select whole row").click();
cy.get("body").type("{ctrl+v}"); // fails here
// Row count should increase
cy.get("rowClass").should("have.length", rows.length + 1);
});
cy.get(id).focus() or cy.get(id).click() doesn't work.
Only explicit click via mouse on an element works (while cypress is running tests in UI mode)
How to simulate explicit click in cypress?
Related
I'm trying to make Greasemonkey script that clicks on a button at intervals and also clicks on it at the first load without wait.
I made this code which clicks every 120 seconds but the first time the page loads I have to wait 120 seconds for the code to click the GO button or I have to manually do it. :
window.setTimeout(function(){document.getElementById("masterPage_cphPageBody_btnGo").click()},120000)
and here is the source code related to it from the website
<input id="masterPage_cphPageBody_btnGo" name="masterPage$cphPageBody$btnGo" value="Go" onclick="SetSearchDate();showWaitpage();" class="btn2" type="submit">
How can I add a line to click on the GO the first time the page loads and 120 seconds there after?
the webpage before and after pressing the GO button has the same exact URL so adding the click on GO button without wait time will send hte page into a loop of
URL loaded GO clicked
URL Loaded GO clicked
URL Loaded GO clicked
...
checked the differences of the page before and after the first time GO button is clicked...
so I need the script to click Go button immidiately only if the following page does NOT show on the page
<span id="masterPage_cphPageBody_lblSelectAvailableTime" class="bodyBold">Select an available time</span>
but if "Select an available time" text show on page the script should wait 120 secon
I'm running: Greasemonkey, Windows 8 64, Firefox
Use a named function instead on an anonymous one (Often a good idea anyway).
Then use document.querySelector to check if that element is present. (That function has much more flexibility than getElementById.)
So your code becomes:
if (null === document.querySelector ("#masterPage_cphPageBody_lblSelectAvailableTime") ) {
clickGoButton (); //-- Initial, immediate click.
}
window.setTimeout (clickGoButton, 120000);
function clickGoButton () {
document.getElementById ("masterPage_cphPageBody_btnGo").click ();
}
Considering the post and pre Go button URL are the same to avoid the boot loop I found a textual difference between post and pre click and used it to avoid the loop
here is the code that worked for me at last
if (/Select an available time/i.test (document.body.innerHTML) )
{
window.setTimeout (clickGoButton, 120000);
}
else {
clickGoButton ();
}
function clickGoButton () {
document.getElementById ("masterPage_cphPageBody_btnGo").click ();
}
For a web page I am trying to write a test for, a modal appears sometimes. I'll like to write the test case such that if that does happen, I'll click the x to exit out of it and continue on with the test, else just do the test.
So far I have this:
client
.init()
.url('https://www.mywebsite.com/')
.isExisting('#simple-modal.auth-modal.open.visible').then(function(value){
// Select the X button: would like to client.click('#xbutton')
//when modal finishes loading
})
.click('#mybutton')
.getText('.browse-header').then(function(value) {
console.log('Title is : ' + value);
})
.end();
It seems that if I try to split the client object into 2 sections such that I init() and declare the url, then add a semicolon, then figure if the modal exist, add semicolon, then complete the rest of the test, the client doesn't complete the test. What can I do?
I'm writing a test for my angular app.
I'm using protractor with jasmine.
The process in the page is as follows:
1) click a button|
2) handler creates a div with content : bar|
3) element(by.id('foo')).getText().then(function(data) { var some-var-i-declared-earlier = data });|
4) click a button which removes this div from DOM|
5) expect assertation for this element value.|
the problem will this promise is resolved the element is not present and thus I get null.
if i do expect (which resolves the promise) before I hit the button which removes the div I can see the value I need
the problem is that the flow must remove the div before i do expect.
how can I force the promise to resolve to get it's value?
of course any other solution is very welcome.
thanks in advance!
1) click a button| 2) handler creates a div with content : bar| 3) element(by.id('foo')).getText().then(function(data) { var some-var-i-declared-earlier = data });| 4) click a button which removes this div from DOM| 5) expect assertation for this element value.|
element(by...).click(); // step 1
var text = element(by.id('foo')).getText(); // step 3
element(by...).click(); // step 4
expect(text).toEqual('the-right-value'); // step 5
The reason why your original isn't working when you just assign the text data to some-var-i-declared-earlier is because this value is assigned in a promise. This means that by the time you reach the assert statement, the assignment hasn't been done yet (read https://github.com/angular/protractor/blob/master/docs/control-flow.md). In fact, step 1 hasn't even been executed by the time your assertion runs.
Alternatively you can do this (which helps you understand what's going on, but is less concise compared to the first answer):
element(by...).click(); // step 1
var some-var-i-declared-earlier = null;
var text = element(by.id('foo')).getText().then(function(data) {
some-var-i-declared-earlier = data
}); // step 3
element(by...).click().then(function() { // step 4
// the fact that this is run inside the 'then' makes sure it executes at the end of step 4
expect(some-var-i-declared-earlier).toEqual('the-right-value'); // step 5
});
I want to make input type="file" becomes available and clicked only when I click on some element, which is also activated it (for example, stylized span).
For this I have the Javascript parameters on span:
onclick="document.getElementById('upload_hidden').Disabled = false;
document.getElementById('upload_hidden').Click();"
But the trouble is that in Firefox only first click removes the input attribute disabled and second - opens the file selection window. In Chrome - all OK: input become enabled and clicked by first span click.
Why, first click in Firefox does not work ? :(
http://jsfiddle.net/ey47G/
P.S. In firefox v21 - all OK. Firefox v25 and v26 - have this trouble.
I could imagine that the script is already ahead when it tries to click the button - but the button is still disabled
var f = document.getElementById('f');
var s = document.getElementById('s');
s.onclick = function () {
f.removeAttribute('disabled');
setTimeout(function(){ f.click(); }, 100); // run the explorer after 100 ms
}
This does work.
http://plnkr.co/edit/9syOfSJHaJ4b3bhRufpv?p=preview
I have two buttons "Next element" and "Previous element" and some custom widget containing CellList.
On button clicks I call to my widget's method which changeselection in CellList by calling it's SelectionModel:
selectionModel.setSelected(value, true);
When I refresh CellList's contents, the buttons work just fine, but when I select element in list by clicking on it, this behavior happens:
For example, I have elements {0, 1, 2, 3, 4, ..} on the list. I click on element 1, then press "Next element" button two times. These SelectionChangeEvent occurs:
Change selection from 1 -> 2 (on first button press)
2 -> 3 (on second press)
3 -> 1
But after step 2 if I press "Previous" it correctly go back to element 1. So element that I clicked with mouse doesn't let selection go more than 1 step around it.
I have no idea where the third event is coming from. My only guess is that manual selection event continues pending after firing, but I don't know how to check that.
Anybody knows the reason of this problem?
upd:
I found confirmation that selection by clicking event continues to hanging there somewhere in the EventBus: when I change search filters I access SelectionModel the same way as on button clicks and set selection to first element. But if there was user click on CellList before that the same thing happens: first, selection changes to 0, second, it goes back to previously selected if new selection of data contains that element.
upd (for Ümit's question):
nextButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
/* Omitting checks that there are elements on the list,
some element is selected and isn't last */
T value = dataProvider.getList().get(currentIndex() + 1);
singleSelectionModel.setSelected(value, true);
singleSelectionModel.isSelected(value);
Element rowElement = cellList.getRowElement(index);
rowElement.scrollIntoView();
}
}
upd: Found what was causing this problem: http://code.google.com/p/google-web-toolkit/issues/detail?id=6310
It seems you need to use HandlerRegistration. So multiple click event is not called.
Refer to:
GWT Handler Registratin
and
related link