-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chromy.wait(fn) in script context #20
Comments
Ok, I have worked around this one. This option may be useful to some devs later on -- but probably not an important feature. Closing issue. Thanks. |
Here's one of them. I'd like to implement casperJS' chromy.click('.some-button');
chromy.wait(function () {
return !chromy.visible('.loading-spinner'); // wait for the loading spinner to disappear
});
chromy.click('.somewhere-else'); but of course it doesn't work. Is there anyway to achieve the above? |
chromy object can not be accessed in the function passed in .wait() chromy.click('.some-button')
.wait(function () {
let dom = document.querySelector('.loading-spinner')
return dom !== null && dom.offsetWidth > 0 && dom.offsetHeight > 0
})
.click('.somewhere-else')
.end() |
thank you very much @dotneet for your reply! Yes i figured that out eventually, but now the problem is that given that the var selector = // some selector that you get programmatically
chromy
.click('.some-button')
.wait(whileVisible(selector))
.click('.somewhere-else')
.end();
function whileVisible(selector) {
return function () {
var dom = document.querySelector(selector); // can't access `selector`
return dom === null || (dom.offsetWidth <= 0 && dom.offsetHeight <= 0);
};
} I'm trying to migrate from CasperJS to Chromy to maintain a BackstopJS suite of more than 120 tests, and it's not really feasible to write something like that over and over across all tests. The same applies if I wanted to implement something similar to Is there any way to do something like that ^ currently in Chromy? And are there any plans to either allow Thanks a lot! EDIT: also it's not really just a matter of avoiding copy-pasting, I have some code like this that I can't figure out how to make it work /**
* Opens a tab on the page, and waits for the content of the tab to be on the DOM and visible
*/
function openTab (tabId) {
var tab = require('./tabs/' + tabId);
chromy.click('#' + tab.id);
// this doesn't work, because i need the element to also be visible, not just in the DOM tree
chromy.wait(tab.readySelector);
// this doesn't work, because the `wait()` function can't access `tab.readySelector`
chromy.wait(function () {
var dom = document.querySelector(tab.readySelector);
return dom !== null && dom.offsetWidth > 0 && dom.offsetHeight > 0
});
} |
@AkA84 |
@dotneet amazing! thanks a lot! |
Hi @dotneet, I discovered that .wait(fn) runs in the chrome window context. Is there a way to run this in the chromy script context?
The text was updated successfully, but these errors were encountered: