CodeceptJS: Launch a page with dynamic query string - codeceptjs

I have a page which needs to be launched with a query string that's generated after a sendPostRequest call.
async goToPage(){
const pageId= await I.sendPostRequest(url);
I.amOnPage(/details?id=${pageId});
}
I am calling this method in my step file.
Issue that am facing is, page that's generated in report is blank, even if I call a static page it's blank. But if I remove the async, await then I can see the page in report generated.
Basically when I call a page after a await, the page is not redirected even though I can see pageId query string has the value returned after the post call.
Please assist on the same.

You forgot the backticks.
I.amOnPage(`/details?id=${pageId}`);

Related

JSF ui:debug causing NullPointerException

My JSF application has a <ui:debug> tag in the top level template. I have a data item creation page that saves the item to the DB. The DB then returns the saved item which I store in the JSF flash. I then redirect to a new page and display the item that I retrieved from the flash. When I view the page, the Debug page is shown with a NullPointerException and sometimes there is no stack trace and other times there is a stacktrace similar to (don't pay attention to the specific line numbers.
NullPointerException
at com.sun.facelets.util.DevTools.writeVariables(DevTools.java:158)
at com.sun.facelets.util.DevTools.writeVariables(DevTools.java:144)
at com.sun.facelets.util.DevTools.debugHtml(DevTools.java:135)
at com.sun.facelets.tag.ui.UIDebug.writeDebugOutput(UIDebug.java:92)
at com.sun.facelets.tag.ui.UIDebug.encodeBegin(UIDebug.java:81)
...
If I remove the <ui:debug> tag, then my page is successfully displayed. What is causing the NullPointerException?
Part of the job of the <ui:debug> tag is to display the contents of all the various JSF scopes including the "flash scope". DevTools.writeVariables is a helper function that is used to turn the objects in the scopes into something readable to display in the debug page. It uses methods like toString() to display the objects. The object that was stored in the flash, overrode the toString() method with the following boilerplate code
#Override
public String toString() {
//TODO: Supply implementation
return null
}
Since the toString() was returning null, it later caused a NullPointerException. If you properly implement toString(), this error will not occur.

Rendering Page in SessionScoped

I am facing a Problem using #SessionScoped in JSF. When traversing from Home.jsf to Dashboard.jsf with some Query String parameters, Dashboard.jsf page is working fine as per the input in QueryString parameter.
But, when i am going back again(BROWSER BACK BUTTON) to Home.jsf and click on some other link for Dashboard.jsf, the same is not updating the Page as per the Query String. It is displaying me the Same page i requested previously.
When i debug the code, i observed, that on first request it is going to code behind PageBean(Dashboard.jsf), but, on another request, it's not.
I don't want to use #RequestScoped and #ViewScoped because i've to maintain the values in the Session.
Can anybody suggest how can i render the Dashboard.jsf on every request?
Please Suggest.

Determining the previous page in mvc 3

How to check the previous page in mvc 3 application.
Previous Page.
On click of the above link I have to go back to previous page.
How to do this ?
This will depend on how is the navigation organized on your website. One possibility is to use the history.go(-1) javascript function which will simply simulate the browser back button:
Previous Page.
Another possibility is to have the calling page pass a ReturnUrl query string parameter to this page which could be used to construct the link:
Previous Page.
Of course this assumes that when you called the controller action that rendered this view you have passed the ReturnUrl query string parameter.
Same as Matthew's answer but using a session variable. That way you could update it selectively in the Action you want. For example, on a POST action you wouldn't want them to go back to that view with form values there. What you really want is for them to go back to the page before that.
public ActionResult MyNextPage(string prevUrl)
{
Session["prevUrl "] = prevUrl;
View();
}
Then in the View:
Previous Page
Note that if session is expired or null it will throw an exception.

ActionResult return to page that called it

I have a ActionLink, that calls my public ActionResult, and I would like it to return back to the page that it was called from, but how?
There are a couple of tricks that you can use for this.
The simplest is ...
return Redirect(HttpContext.Request.UrlReferrer.AbsoluteUri);
AbsoluteUri may not give you the exact path you are looking for, but UrlReferrer should have the imformation you are looking for. Redirect returns a subclass of ActionResult so it is a valid return value.
Another idea is to base the redirect location off of stored values. This is useful when you are going to make multiple requests before you want to redirect, such as when you validate a form and show validation issues on the first response. Another situation will be when the referrer is not a local site. In either case, your referrer won't be what you want it to and you will need to retrieve the correct location from somewhere else.
Specific implementations include using a hidden input field on your form, session state, pulling a descriminator value from your route data, or even just a more constant value like HttpContext.Request.ApplicationPath.
Good luck.
Keep in mind that due to the state-less nature of the web, your ActionResult isn't "called from" your ActionLink as much it is simply a url that the user-agent requested.
Because of this, the only real "built-in" way you can know where that user was coming from is by inspecting the http Request headers to see what the referring page was:
string referrer = Request.Headers["referer"];
You'd then be responsible for parsing out the Action method from this url, if you were going to call it directly. Be aware that this referrer may not be a link within your own site.

MVC Controller Called twice

I have a Product controller with Index action, which basically creates the view form for post and Index (Post action verb) action on the ProductController which basically save the product to db but when validation errors occur, I am returning a View(mymodel) else when saved, I am returning RedirectToAction("Created,"Product") but for some odd reason when I break into the code , it is hitting the Product Controller action twice rather than just once. Hence the product has 2 records instead of one.
public ActionResult Index()
{
return View()
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(FormCollection fc)
{
// 2 calls are made to this controller
try
{
// save the product
return RedirectToAction("Created");
}
catch(Exception ex)
{
// recreate the model from form collection
return View(viewData); // when a validation error occurs it comes into the catch block
}
}
Sometimes I have found Firebug to cause this behavior. Try disabling its Script panel, if you have it installed.
Explanation: In some cases Firebug isn't able to get the script sources for the display within its Script panel. In these cases it initiates a second request to get them. See issue 7401 for some discussion about this, which alleviates the problem and is fixed with Firebug 2.0.2.
Here's a basic checklist (copied from here):
Check that you don’t have any image or another elements in the View with an
empty src attribute (<img src=”" /> for example) or have src
attribute referencing something that no longer exists. You better
check directly in the browser's “Page Source”, than in the View itself due to the
possibility of some “dynamic” issues when the View is rendered. Once you
find such empty element in the page's HTML source its usually trivial to
find the same element in your View and fix the issue. This can also happen with <link href="">.
Check that you don’t have any AJAX calls referencing an empty URL (browsers will interpret such empty URL as the current page and will request the current page again making the Controller action execute few times).
You forgot to return “false” from the JavaScript click event handler for a link or button that makes an AJAX call. If you forget to “return false”, the browser simply interprets the default action of the link – regular, non AJAX, calling the same page again)
Sometimes Firebug and YSlow [ Firefox (FF) plugins ] can cause such issues. Just temporarily disable them in FF or test with a different browser.
Watch out for duplicate filters decorating your controller or action. (this was my problem)
Another solution for this case..
I had exactly same problem, running and testing from Chrome. I couldn't debug it because the second call was coming from (external call). I have randomly tested it in Firefox and Internet Explorer where there was no double hit.
Whatever nasty thing it was, I have deleted Chrome cache (everything!!!) and problem has been resolved.
Hope it will help some of you :)
I had a similar issue with a controller action that generated an image, and I was only seeing it with Firefox. There is a really old bug that causes this, that I guess is still there.
https://bugzilla.mozilla.org/show_bug.cgi?id=304574

Resources