I have a button and every time I press it should either show me the completed or uncompleted.
I tried to think of how everything should work. But can't figure out how to sort them properly, loop through all or loop through all completed.
tasks.forEach((task) {
if (task.completed) {
list.removeAt(task);
} else {
list.insert(tasks.indexOf(task), task);
}
});
The first press should show the completed only and next press only the uncompleted and it keeps going on like that.
Use where to filter out items from the list:
List completed = tasks.where( (task) => task.completed).toList();
Related
so in ionic 3 there was registerBackButton() but in ionic 4 this option is no longer there and has been sitting on the shelf for quite some time now.
I have read the post here that tries to solve the solution I am looking for, however, the back button still performs as it wants to.
this SO answer shows another way but it is the same idea of intercepting and navigating, however, I am just, for now, trying to dismiss the top modal in the stack.
scenario: users open a search modal(modal1) which then they click on a users profile modal(modal2). The person wants to go back to the search modal(modal1) but instead of clicking the nice button that allows them to do that, they use the hardware back button.
result: all modals(modal1 and modal2) are closed.
desired effect: using the hardware back button will allow for custom navigation based on logic in place.
attempted code:
this.platform.backButton.subscribeWithPriority(0, (): void => {
this.modalCtrl.getTop().then(
async (value: HTMLIonModalElement): Promise<void> => {
if (!!value) {
await this.modalCtrl.dismiss();
} else {
this.navCtrl.navigateRoot('/home');
}
},
);
});
also have tried :
// registering back, if there is a view on top, close it, don't go to home.
this.platform.backButton.subscribeWithPriority(0, async (): Promise<void>=> {
try {
console.log('try');
const element = await this.modalCtrl.getTop();
if (element) {
console.log('in true');
await element.dismiss();
}
} catch (error) {
console.log('error closing modal', error);
}
});
note when pressing the back button I never see ANY of the console logs... maybe things have changed a lot more? since the previous Stack overflow questions.
UPDATE:
If you are having this same issue then know you are not alone!
This, and many others are well known, see here for a list they are tracking the issues. Nothing else to do... but wait... I guess...
I will update this when there is a change
I want enter window and wait till element is present. Problem is, when i enter this window, this element is present and clickable, but after short time progressbar apper, and window is blocked till this progressbar works. How to wait properly for elements ?
I tried below code, doesn't work, but it show what i want obtain (click addButton, wait for progressbar or 5sec passed, and then wait for element id displayed.
this.openWindow = function(addButton, progressbar, targetElement){
addButton.click().then(function(){
browser.driver.wait(progressbar.isDisplayed(), 5000).then(function(){
browser.driver.wait(targetElement.isDisplayed(), 5000);
});
});
};
Checkout official documentation for stalenessOf:
You should do something like this
this.openWindow = function(addButton, progressbar) {
var EC = protractor.ExpectedConditions;
return addButton.click().then(function(){
return browser.driver.wait(EC.stalenessOf(progressbar), 5000, 'Progress bar was not hidden within 5 sec');
});
};
And then you can use your function like this
openWindow(addButton, progressbar).then(...)
The code above will be resolved when progress bar has been hidden or will fail if time is out.
If progress bar is not completely removed from DOM, you can also try invisibilityOf
I currently have the following code in one of my test specs for Protractor:
.then(function() {
return button.click();
})
.then(function() {
return element(otherButton).isDisplayed();
})
.then(function(otherButtonIsPresent) {
if(otherButtonIsPresent) {
return browser.wait(EC.elementToBeClickable(element(otherButton)), getWaitTime())
.then(function() {
element(otherButton).click();
return element(continueButton).isPresent();
})
}
})
When I use Chrome to debug using the --debug-brk and --inspect flags, I am able to pass these checks and resume as normal. When I run the same test without the flags, the test fails and stalls during looking for otherButton before trying to click on it.
I'm wondering if this is because during debugging, I set breakpoints and wait for the buttons to show up on the screen before attempting to click on them.
I need to make sure that this element is visible on the page before trying to click it and was wondering if there were another way if accomplishing this?
Thanks
I'm using Answer as I can't comment yet.
You're basically mention it yourself: after you clicked a button you just want to wait until a next button is clickable.
Therefore your .then()-functions should start from the button it depends on. To me it seems, the three lined-up .then()-functions depend on the same condition, so after you .click() the first button, the second .then() gets immediately executed, not waiting the previous .click() to finish.
Therefore putting the .then() directly behind the relevant .click() and inside the preceding .then()-function, this should work:
.then(function() {
element(button).click().then(function(){
element(otherButton).click().then(function(){
return element(continueButton).isPresent();
});
});
});
Or if you go with ExpectedConitions, you shouldn't need .then()-functions. Because Protractor should manage the ControlFlow, allowing you to write it without chained .then()-functions:
.then(function() {
browser.wait(EC.elementToBeClickable(element(button)), getWaitTime());
element(button).click();
browser.wait(EC.elementToBeClickable(element(otherButton)), getWaitTime());
element(otherButton).click();
browser.wait(EC.elementToBeClickable(element(continueButton)), getWaitTime());
return element(continueButton).isPresent();
});
This nice post elaborates a bit on asynchronous writing, but thanks to Protractor synchronous execution.
As alternative an example combining my both inputs, kind of double-securing the test:
.then(function() {
browser.wait(EC.elementToBeClickable(element(button)), getWaitTime());
element(button).click().then(function(){
browser.wait(EC.elementToBeClickable(element(otherButton)), getWaitTime());
element(otherButton).click().then(function(){
browser.wait(EC.elementToBeClickable(element(continueButton)), getWaitTime());
return element(continueButton).isPresent();
});
});
});
I have a test case where I create certain objects through REST APIs. The creation of that object takes about 4-5 mins. I want the test to wait till the creation is complete and validate that the object was created. Is there a way to achieve this long wait with protractor? (I have tried many things but nothing seems to be getting me closer to what I'm trying to achieve)
The reason why I need to validate (apart from making sure it works) is that after that I need to test deletion of that object and don't have a way to make the tests wait till the creation was complete.
Code for test
it('should create object', function (done) {
//create objects (click on submit buttons basically this part works fine)
var addButton = homePage.addButton;
for (var i = 0; i < 2 ; i++){
addButton.get(i).click();
}
// in my page after I click creation it shows a loader for each item and
// till it completes. When it completes it shows the item itself without
// the progress bar
var pendingObject = element.all(by.id('.throbber-loader')).then(function (items) {
return items;
});
while (pendingObject) {
pendingObject = element.all(by.id('.throbber-loader')).then(function (items) {
return items;
});
browser.wait(constants.SLEEP.MS2K);
}
// the pending objects are completed so I should be getting 0 of them
// and 2 created
expect(pendingObject.count()).toEqual(0);
var finishedObj = homePage.getItems;
finishedObj.then(function(items){
expect(pendingObject.count()).toEqual(2);
})
done();
});
Appreciate any pointers.
For a project I'm currently working on am trying to reach the following:
I have a simple page, on this page are 4, hidden and not visible elements,
they are simply formatted as this:
Basically all i want, is too build a sort of Easter egg, so when a user clicks these buttons in a specific order, i.e. link_4 -> link_1 -> link_3 -> link_2
it triggers a certain event, whatever this might be.
Ofcourse the event could only be triggered if the right combination/order of clicks have been done.
Any ideas how to go about this using jQuery?
var click_order = [];
$('a').click(function (e) {
click_order.push($(this).index());
if (click_order.slice(-4) == '3,0,2,1') {
// easter egg stuff
}
});