Cypress - if function with timeout - automated-tests

I have problem. I want to try to find an element (1) for 60 second timeout. If Cypress will not find it, then it must not end as failed test but click on other element (2) and after that take screenshot and end as failed
It's because if this element (1) is not find it means that some feature in app failed. After I click on second element (2) I will find what was the problem and why it ended like that. That's because I want that screenshot after that.
Is there anyone who knows to resolve this?

I think this should achieve what you are looking for -
cy.get("body").then(($body) => {
// synchronously query for element
if ($body.find("element").length == 0) {
cy.get('locator').click()
cy.screenshot(filename)
}
else {
// do something else
}
})

Related

How to check if useRouter can use router.back() in nextjs app

I'm using next js for my application and I'm facing some issues with routing to the previous route of the application. I know that there is a function like router.back(), but I do not know if I can go back from the current page.
I have read that we can check history.action !== 'POP' but now I check that history has no action property when using console.log(history)
I am using next/router.
Way too late to be useful but for the next person that comes along: If I read your question correctly, you're wanting to know if there is something in the navigation stack that you can navigate back to - and you want to do something else if there is no history.
You can use window.history.state to get a glimpse; although it doesn't give you clear access to the history stack the state has an "idx" property that is incremented when a location is added to the history stack. This means that if window.history.state.idx is zero there's nothing in the history stack, if it's bigger than zero then there is something in the history stack and you can navigate back.
An example for navigating back if you can or doing something else if not:
if (window.history.state && window.history.state.idx > 0) {
router.back();
} else {
// Do something else
}

UIAlertView giving constraint errors

i have the following code to present an alert with different messages when problems occur in my app.
the code has worked fine for years, and is in most of my applications on the App Store.
i am making a new app, and simply added this code in, however i am seeing the error messages below in the console, which i can not get rid of.
the constraint message refers to the alert width, but i have no constraints set , and no means to adjust any to silence the warning.
can somebody please advise what's going wrong.
thanks
-(void)errorMessage:(id)sender
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(#"Information",)
message:displaymessage
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *firstAction = [UIAlertAction actionWithTitle:NSLocalizedString(#"OK",)
style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
[self dismissViewControllerAnimated:NO completion:nil];
}];
[alert addAction:firstAction];
[self presentViewController:alert animated:YES completion:nil];
}
2019-04-18 09:17:54.785207+0100 TestInputView5[1380:28232] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x600001e15b30 UIView:0x7fe60c6104e0.width == - 16 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600001e15b30 UIView:0x7fe60c6104e0.width == - 16 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
I have found a solution on a Russian forum.
It looks like magic, but it works.
You need to do two things:
1) Add an empty view to an Alert
2) Show it without animation
alert.view.addSubview(UIView()) // I can't explain it, but it works!
self.present(alert, animated: false)
Credits to the forum: https://quares.ru/?id=33972
The post is machine-translated, so I suppose there should be an original in English somewhere (I couldn't find it)

How do you debug Firestore security rules?

I'm crying myself to sleep on this one.
My getAfter is returning an object that only has 1 field, as every other field type is incorrect. Which I have no idea how to check without any debugging tools (I can't see the data, so its all guess and check).
Here is a watered down version of my rules for users.
match /users/{userId} {
function isValidUser(user) {
return user.id is string &&
(user.address is string || user.address == null) &&
(user.dateOfBirth is number || user.dateOfBirth == null) &&
user.email is string &&
user.name is string &&
(user.phoneNumber is string || user.phoneNumber == null);
}
function isValidWrite(userId, user) {
return signedIn() &&
writeHasMatchingId(userId, user) &&
isValidUser(user);
}
allow read: if signedIn();
allow create: if signedInAndWriteHasMatchingId(userId) &&
userHasId(userId) &&
isValidUser(request.resource.data); // Tested
allow update: if isValidWrite(
userId,
getAfter(/databases/$(database)/documents/users/$(userId))
);
}
and this is the transaction I am trying to run.
const user1Ref = this.userCollection.doc(user1Id);
const user2Ref = this.userCollection.doc(user2Id);
const batchWrite = this.store.batch();
batchWrite.update(user1Ref, {
"details.friend": user2Id,
});
batchWrite.update(user2Ref, {
"details.wishlist": true,
});
batchWrite.commit();
If I comment out the isValidUser(user) line, the operation succeeds. If I leave any line uncommented out inside the function isValidUser(user) except user.id is string, it fails.
Why would the getAfter document only have the id field and no others when they are listed in the Firebase console? Is there a way to output or debug the value of getAfter so I can see what it even is?
I'm answering based on just one line of your question:
Is there a way to output or debug the value of getAfter so I can see what it even is?
There kind of is - at least in 2020.
When one runs something in the Rules Playground (Rules Simulator, see bottom left), the steps taken in the rule evaluation are shown like this:
This list sometimes gives indications that help figure out what the rules evaluator is doing. It's a bit tedious that one needs to 'click' the steps open, individually, instead of seeing true/false just by glancing. But it's better than nothing.
Note: I presume this feature is under development by Firebase. It sometimes seems to give wrong information - or I have failed to read it correctly. But it may help, and looks like a good place for providing such information to the developers. We really would like to see: with the current data, the built query document, and the rules, how does Firebase see it and why does the rule evaluate to true or false?
Another approach, not mentioned here yet and likely not available at the time the question was raised, is wrapping your rules with debug().
Why this is cool?
Allows to see the values suspected of not being right; I still use the same comment-out-narrow-down method that #ColdLogic nicely described in one of their comments
Why this is not enough?
There is no tagging about which value was output; just eg. int_value: 0. Debug would benefit from eg. printing the first 10 letters of the equation it's evaluating, in the output.
Security Rules rejection reasons are still awfully short, as false for 'update' # L44.
the line number always points to the main expression being evaluated. Never to a function called, or a subexpression with && that really causes the fail.
Firebase could fix this (not change the output syntax; just give a more detailed line number). That would eliminate the need to comment-out-and-narrow-down.
The output goes to firestore-debug.log (fairly hidden), so one needs to open yet another terminal and keep an eye on it.
Debugging Security Rules is unnecessarily difficult - and I'm afraid it means people don't use their full potential. We should change this.

String disappears when I use String.Substring

I am using ASP.NET to create the website. But on my way, I was told to use string.Substring(int, int) to create a substring when the length increases.
I also searched for a better option here about the character limit in ASP.NET but either they were for ASP.NET Web Forms or they were for C#, but I am using ASP.NET Web Pages.
The code that I am using is this:
#if(message.Length > 80) {
message.Substring(0, 80);
} else {
<text>#message</text>
}
The issue is that, when the character count is under 80 the message is shown to the user, but when it exceeds the limit (above 80) the message is not viewed. However, I have tried to show 3 messages at a time one with a length 10 other with 25 and the last one with 117, the last one was not shown. As it had to pass the first block. The other who passed from else block. They got written down.
I think there is some kind of bug in the block, but I am not able to figure it out. I also want a better suggestion to break the string, where the character limit catches up. I want to break the string where the character limit 80 comes up. Any good idea of how to do this? If the substring is the best then please guide me.
In else part you have written
<text>#message</text>
But this is missing in if block.
Please add this to if block
if(message.Length > 80) {
message= message.Substring(0, 80);
<text>#message</text>
}
else {
<text>#message</text>
}
I hope it will help you.

Not sure why my program seems to be skipping some functions?

Hey there,
I'm a little confused with some Actionscript I'm working on. For my GUI, I have written four functions for times when computing is taking place. These are showMessage("Loading Text..."), disableButtons(), clearMessage(), and enableButtons(). They work great throughout the program. ShowMessage displays a loading message, disableButtons disables buttons so no one can click anything, clearMessage clears the loading message when job is done, and enableButtons turns them all back on.
For some reason, there is one button click handler which is giving me troubles and I'm not sure why. I've set it up just like others similar to it (which all work) but this one doesn't display the message or shut off my buttons. Here is my clickHandler...
private function Buffer_Route_clickHandler():void
{
showMessage("Loading RBE Options");
disableButtons();
if(Buffer_Route.selected && rbeAC.length == 0){
createRbeAC();
}
}
And here is the creatRbeAC function...
private function createRbeAC():void
{
rbeAC.removeAll();
hiddenRBELayers.removeAll();
var rbeIDs:Array = rbeConfigList.getKeySet();
for each (var rbeID:int in rbeIDs)
{
var rbeConfig:Hashtable = rbeConfigList.find(rbeID) as Hashtable;
var rbeData:Object =
{
restURL:rbeConfig.find("rbeRESTURL") as String,
layername:rbeConfig.find("rbeLayerName") as String,
icon: rbeConfig.find("rbeIcon") as String,
titlefield: rbeConfig.find("rbeTitleField") as String,
checked: rbeConfig.find("rbeChecked") as String,
count: "0" as String
};
if(rbeData.checked == "false")
{
hiddenRBELayers.addItem(rbeData.layername);// as String);
}
rbeAC.addItem(rbeData);
}
}
I wasn't getting any loading text, so I took out my clearMessage and enableButtons functions from the code to see if it was adding the message and disabling the buttons to begin with. I am still not getting anything though. Since clearMessage and enableButtons is no where to be found in this button click handler or creatRbeAC function, then I can not understand why the loading message and buttons aren't disabled, even when the computing is finished.
Some things to note. If I comment out the creatRbeAC function, the loading message shows and buttons do disable. Its almost as if those functions are being ignored when the creatRbeAC function is in the code.
Any help? I would greatly appreciate it. Hopefully I have provided enough information.
in my actual app, i have similiar problems.
In my Eventhandler (it doesn't matter, if there is a button handler or a mouse handler), I also wan't to disable the app and use some filter functions for my arrayCollection.
Unfortunately, this action seems to need too much ressources, especialy, when the app run in debug mode. I have to waint for the next screnn refresh. So i try to implement the "applyFilterMethod" in my eventhandler with
callLater(applyFilterMethod)
but it also wo't work.
Finally, the setTimeOut(applyFilterMethod,500)
solved my issue. So, try it with the timeout-method, if you have luck.
BR
Frank

Resources