TestCafe - Possible to set "preserveUrl" to some own value? - redirect

I use two roles in my project.
In Role1, after a couple of clicks, I come to a page with URL1 "http://acc.comp.se/signing-page". On this page, there is a Button "SignWithCustomer".
If I click on that button I will get redirected to a page with URL2 "https://acc.comp.se/LogIn/?returnUrl=webben"
Now, in real life this redirection would be a new tab, i.e. I can always go back to the first tab where URL1 is still present and continue there as if the redirection never happened.
Is there a way to save the URL1, i.e. is it possible to set the preserverUrl to something I want? Like "preserveUrl=ClientFunction(() => window.location.href)"
I want to go back to Url1, the URL just before the last button click. And I want the previous session (before redirect) to be saved.

Please find our example in the corresponding guthub thread, where we discussed a similar inquiry based on your scenario.
At present, TestCafe supports Multiple Browser Windows. You can try this feature in your scenario.

Related

Play Framework: clear Flash scope when going back

I'm using scala 2.11.8 and Play Framework 2.3. I am submitting a form and managing the result through a controller. The controller returns a Redirect to a page flashing a certain message, either a success or an error message:
Redirect(routes.MyController.page).flashing("success" -> "All went well")
I then manage this message using javascript, so it can be seen in a modal:
#flash.get("success").map { message =>
<script type="text/javascript">
modalSuccess('#message');
</script>
}
All goes well, the modal is shown. Next I navigate to another page and use the Back arrow to go back and the modal is shown again. This is, of course, very weird for the user: he has just clicked back, it makes no sense that he sees a "All went well" message.
Previously, I passed these messages as parametres to the pages and returned a 200 OK:
Ok(views.html.page(message = "All went well"))
But the exact same thing happened because the request was sent again. I switched to Flash to solve this, but I can't seem to prevent it from showing when returning to the previous page.
Should I clear the Flash scope, or should it clear by itself, once the redirect is executed?
When you click back, by default the browser will serve the page out of its cache, it won't reissue the request, and that is what is happening here, it has nothing to do with Play.
There is no standard for how the browser back button behaves, in particular with regards to caching, so solving it isn't straight forward because all the browsers behave differently. This SO question/answer covers it fairly comprehensively:
How to control web page caching, across all browsers?
But be aware of the drawbacks, if you tell the browser it must never cache pages, you can end up giving users a poor experience, for example, if they are filling out a form, and they accidentally navigate away, and then click back so they can continue filling out the form, if you force the browser now to cache the page they will lose everything that they entered into the form.
Also, what if the reason they are clicking back is that they want to see the rendered model again? When users click back, they expect to see the page that they were just on, just as it was. If you change that, you're breaking their expectations. I wouldn't be happy if that happened to me - I hate it when I click back and I get a different page, you're probably going to upset your users if you do it.

Logout functionality in OutSystems

I am working on web app in OutSystems 10.0. In the application, if I log out, it logs off. But when I click the browser back Button, it redirects to the Previous page (which should be displayed only after login). Any suggestions?
You probably need to have roles on the pages, if the pages have the role anonymous anyone can open it.
You're probably accessing the website via http and not https, so when you press back on the browser it will show you a cached version of the previous page.
Because it's the cached version, the session and roles are not checked.
As a recommendation, force the https protocol.
Following the link provided by #Abdulhakeem, they recommend the following:
Add a hidden input to the page - initialize it to some value (for example 'no') - so when the page is rendered by the server it always has a 'no'
Add a bit of Javascript to the page ready event to:
Check that value - if it's not what you'd expect from the server (in our case, <> 'no'), force refresh the page (see below)
If it is still set to what you'd expect from the server, change it (in our case to 'yes') and do nothing else
I recommend downloading the .oml provided in the post and reviewing how they actually implemented it.
if you can change to https, you can also in every action that is on the page that do changes on the database. check if you have permissions or you are logged. that way if the person tries to do back and do some action you can redirect it somewhere.

What is the best practice for open a new page or redirect page in GWT?

There are some options to open a new page or redirect page in GWT, & I don't know which one is the best?
-Option 1: will redirect the current page to a new page but not opening a new tab.
String url = Window.Location.createUrlBuilder().setHash("!search").buildString();
Window.Location.assign(url);
-Option 2: open a new page on a new tab.
String url = Window.Location.createUrlBuilder().setHash("!search").buildString();
Window.open(url, "_blank", null);
-Option 3: will redirect the current page to a new page but not opening a new tab & retain the states of the previous page
PlaceRequest request=new PlaceRequest(NameTokens.search);
placeManager.revealPlace(request);
In Option 1 & 2, it seems that the system starts to reload the whole page. For option 2, if you press Back button then it will reload the previous page again.
In Option 3, it seems that it does not reload the whole page (ie if you have a header then it won't download the header again). Therefore, it run very fast. If you click Back button then it won't reload the previous page so you can still see all the existing states of the previous page.
Option 3 is quite fast. However, we need to properly reset some variables in the previous page otherwise it will make thing really messy and error-prone.
What is the best practice for open a new page or redirect page in GWT? Which option should we use?
Option 1
Whenever you reload the page, your app has to reload as well. It may happen fast, as the browser caches your code and other static elements, but what is the point? GWT is used as an "app": it resides within a single host page, and changes its state based on user instructions.
Window.Location.assign(url) is only used when a user is leaving your application: either because this user logged out, or because he is not logged in yet, and you redirect him to a login page.
Option 2
Usually, this option is used when you provide a link to a different application/website, and you want to keep your app running.
Option 3
In this option you do not "redirect" "pages". You show different "views" to a user. The web page (host page) remains the same at all times. This is how GWT is supposed to work.

Facebook - click on a like button does not increase the like count

After searching the internet and doing my own research on this subject I still can not find the answer to my problem, so here it is.
When I click the like button (to like my website http://openarchitecture.cz) then the like count is not being increased.
Debugging the FB javascript code on client-side (in Chrome) and examining the ajax response
send back from FB servers after the click on "Like" button, revealed that FB is instructing the Like button to be "disconnected", resulting in the behaviour described below.
The term "disconnected" is a strict FB term (in a sense of a javascript code), it means that on client-side there will be used a "plugin" that will perform certain operations leading to "inactivity" of like button. Technically, when the plugin "disconnect" is beeing recognized as part of the ajax response, there is an array of predefind actions (functions) that will be followed and called sequentially.
Now for the reproducibility of the problem.
Go to http://developers.facebook.com/docs/reference/plugins/like and fill the "URL to Like" field with http://openarchitecture.cz
url.
Click "Get code", then click "Ok" on the pop-up and finally click "Like" button on the right.
The like count should increase. Instead a pop-up shows up for (aprox.) 1 sec.
then the popup disappears. Now I am in the same state as before I click the
like button, i.e. like count is not increased.
I have found similar questions here on SO, but none of them seems to finally
resolve the issue.
The related questions here on SO are:
1. http://facebook.stackoverflow.com/questions/5195183/facebook-like-button-flashing-on-then-off/12958474#12958474
2. Facebook Like button does not work on one website?
One of the suggestions was that this migth actually be a FB bug. I found a (very recently created) bug, reported in FB bug tracking system. The bug is located here:
http://developers.facebook.com/bugs/268340209965207?browse=search_512b8e0bed9724580954683
The bug has however "Low" priority an so far it does not seem to be resolved (it might even be returned as not a FB issue, I am not sure if this possibility is still open).
So for all interested in this.
Is this a real FB bug ?
How have you dealt with this ?
Could it be that my site is for some reason on FB spam/black/"whatever nasty" list ?
Well. This will end up like the other posts, i.e. no lesson learned here.
[The term "page" used later in this post represents the http://openarchitecture.cz page]
I just tried today to like the page again via the FB generated like button (on http://developers.facebook.com/docs/reference/plugins/like/ ) and the result is now ok. So the like count gets increased after clicking the like button.
The difference that I observed when checking the request exchange to FB servers is that this time the communication has been done (by default. i.e. using the XFBML version of the like button) over iframe, not direct ajax call (as was in the past for XFBML).
I dont know what was the cause (I tried the pure iframe version of like button before) but the response going back as a result of the mentioned iframe request is now correct, ie. FB sends back response instructing javascript in client browser to use "connect" plugin not "disconnect" plug-in.
One more thing. One month ago I have created a FB profile (http://www.facebook.com/pages/Openarchitecture/125515934292877) of the page and have done some updates to this profile. So maybe FB decided that the page (being referenced from FB profile) has now earned the provilige to be "liked".
Like I said at the beginning. Problem solved, but no lesson learned.
For me, the problem (Like popup disappearing after a second; "Plugin","disconnect" response) was happening when the Like button URL redirected to another URL.
The fix was to add og:type, og:url, and og:title (required per https://developers.facebook.com/docs/reference/opengraph/object-type/website), then running the URL through the Facebook debugger to clear the cache (https://developers.facebook.com/tools/debug).
More at https://stackoverflow.com/a/16597060/2391566 .

How to find out browser back button click using gwt history

I m using history listener for forward and back browser button.But i m not able to find out history back button click.If any idea plz rply..urgent for me...Thank you..
Your code can use the tokens sent by History management system to determine what kind of action you want to take. Suppose you are at page1 and that page is identified by the token 'page1'. Now, you move to page2. If you click the back button, you will receive the token 'page1'. You can use this to set the state related to page1. See this Google doc for more info.