Weird behavior of GWTP app when hitting "Go Back" and "Go Forward" button of Web Browser? - gwtp

I am using GWTP and I found this issue.
I have this code in CustPresenter:
private List<String> dataList=new List<String>();
#Ovvrride
public onBind(){
myTextBox.setText("Test");
dataList.add("test");
}
Ok, now first time opening the page, the page show the textbox has string "Text" & the dataList has "test" value. While on that page, I hit the "Go Back" and "Go Forward" button of Web Browser (like Chrome or IE). When click "Go Back", then of cause it will show the previous page. When clicking "Go Forward" it will show the customer page & I still see the string "Text" in the textbox of customer page, but dataList has no "test" value?
What is happening?
Is it a bug of GWTP or did i do anything wrong?
Note: I am using GWT 2.50 Last year version

the onBind() method is only called once, when you first instantiate the Presenter. So it populates the TextBox and dataList as you want.
Then when you click back and go forward again what you are seeing is the View that was populated by the first call to onBind(). Pressing forward does not run onBind() again so maybe you are re-instantiating the ArrayList somehow and then NOT populating it because onBind() has already been called.
Try this:
#Override
public onBind(){
private List<String> dataList = new ArrayList<String>();
myTextBox.setText("Test");
dataList.add("test");
}
Or just change onBind() to onReset() or onReveal(), as those methods get called whenever a presenter is revealed.
Someone more knowledgeable may want to correct me here though.

Related

Web browser control, modal window/popup to STAY INSIDE web browser control for Visual Studio 2015/Visual Basic 2015

this is the first time I'm posting a question here; I have searched and searched and searched here and other places and I cannot seem to get any results. I'm using VISUAL BASIC 2015 in Visual Studio 2015. QUESTION: I need to have a modal window/popup from a particular website remain INSIDE the web browser control/window on my form (WebBrowser1); when a particular link is clicked, the modal window/popup jumps out of the form and directly to the user on their screen. I have to keep this popup inside because there are other links to be clicked on that popup, but if it jumps out of the web browser control, no code will work since it's outside WebBrowser1. What I have found is code for older versions, and not 2015; if anything I can even add WebBrowser2 to have the popups/modal windows appear there if possible, just as long as I can code them to keep clicking inside the form. PLEASE HELP! THANK YOU!
window.open (and a click on <a target="_blank"> etc) can be handled via the NewWindow2 event. Hans already pointed out how to do that in comments. NewWindow3 works too, but need at least Windows XP SP2.
As for window.showModalDialog, it is a bit tricky. IE has IDispatchEx (wrapped as IExpando in .Net) implemented on scripting objects so you replace the methods and properties with your own implementation. But window.showModalDialog shows a dialog that has arguments and return values, you need to override those properties in the modal dialog you create too. The code looks roughly like tis:
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//skip events from frames
if(WebBrowserReadyState.Complete!=webBrowser1.ReadyState) return;
if(FindLoginFormOnPage()) {DoLogin();return;}
if(IsWelcomePage()){NavigateToPage1();return;}
if(IsPage1()){SubmitFormOnPage1();return;}
if(IsPage1FormResult()){
var document=webBrowser1.Document.DomDocument as mshtml.ITMLDocument2;
var expando =(IExpando)document.parentWindow;
expando.RemoveMember(expando.GetMethod("showModalDialog"
,BindingFlags.Instance | BindingFlags.Public);
expando.AddMethod("showModalDialog"
,new ShowModalDialogDelegate(this.MyShowModalDialog));
}
......
}
object MyShowModalDialog(string url, object varArgIn, object options)
{
using(FromMyShowModalDialog myShowModalDialog
=new MyShowModalDialog())
{
myShowModalDialog.StartupUrl=url;
myShowModalDialog.DialogArguments=varArgIn;
//omit the code to parse options
//and set dialog height/width/topleft location etc
if(myShowModalDialog.ShowDialog()==DialogResult.OK)
{
//do something on the return value before passing to the scripts
......
return myShowModalDialog.ReturnValue;
}
return null;
}
}
and in the Load event handler of MyShowModalDialog you call something like webBrowser1.Navigate to show the page requested by the parent page.
Now you need to pass the arguments to the webbrowser control on the new form. Do the same as above but replace another property this time.
expando.RemoveProperty("dialogArguments");
expando.AddProperty("dialogArguments")
.SetValue(expando,this.DialogArguments);
This will let the web page access the value passed from MyShowModalDialog and stored in this.DialogArguments.
The earliest you can access the DOM is in webBrowser1_DocumentCompleted. By that time the scipts on the page that read window.dialogArguments are probably already executed and got nothing. After overriding window.dialogArguments, you need to study the script on the page to find out how to revert that. for example, if the page has
<head>
<script>
var oMyObject = window.dialogArguments;
var sFirstName = oMyObject.firstName;
var sLastName = oMyObject.lastName;
</script>
...
<span style="color: 00ff7f">
<script>
document.write(sFirstName);
</script>
</span>
you need to change the values of sFirstName and sLastName then change the innerText property of the span, probably identify via its relationship with a named div or table cell. You can write the necessary changes in a script and call it via HtmlDocument.InvokeScript.
If the page returns a value to its parent, you need to pass it on to your parent form too. Override window.returnValue so when the script writes to window.returnValue it writes to a variable you provided
......
expando.RemoveProperty("returnValue");
expando.AddProperty("returnValue").SetValue(expando,this.ReturnValue);

Unable to operate the prompts of spot fire using selenium webdriver

If anybody has tested spot fire web applications using selenium webdriver please help me. Spot fire uses prompts as popups. And am unable to locate the prompts buttons to click.
Steps i followed:
Save the current window handle.
Get the next prompt window
handle by traversing through iterator(While Loop).
Find the element on new window and click it. But when i printed current
window handle and new window handle are same.
Below is my code
String parentWindowHandler = driver.getWindowHandle();//Stored parent window
String subWindowHandler = null;
Set<String> handles = driver.getWindowHandles();
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext()){
subWindowHandler = iterator.next();
}
driver.switchTo().window(subWindowHandler);
(....My click functions)
I have pasted the fire bug element track below for "OK" Button on prompts.
Next
I have tried to take control using "class" but its throwing exception saying it cant take common/general class.
Please suggest me how to proceed to click a OK button on spot fire prompts.
I forgot to inform.My Prompt contains a "scroll bar" and "Next" button and "Cancel" Button. I need to choose items from scroll bar and press next or cancel button.

Getting the name of a button while the progress bar is going on in webdriver

I have one button named "Add" in my web portal. On clicking on that button a progress bar appears and the name of the button gets changed to "Adding" from "Add" and remains "Adding" until the progress bar is not moved to 100%. After the progress bar is 100% complete, again the text of Add button changes back to "Add" from "Adding".
I need to assert whether the name of the button is changing from "Add" to "Adding" or not during the progress bar movement. But the problem is once I click on the "Add" button, then use the assertion, selenium will first click on "Add" button, completes the progress bar to 100% and then tries to assertion, but now already the text of "Add" button is already changed back to "Add" from "Adding".
Please give the solution. Thanks in advance.
You can find the element, click and immediately return it's text which can be used later for Assert
public string Test()
{
IWebElement element = Driver.FindElement(By.CssSelector("Something"));
element.Click();
return element.Text;
}
Assert.IsTrue(Test().Contains("Adding"));
Note: C# code

Safari Extension: window.open(...) doesn't work sometimes?

I have an injected stylesheet that calls a popup with window...open() on two occasions. One when the user clicks an HTML button, and two, when a user clicks on a context menu item. To listen for the context menu item, I need to add a listener on the injected script like so
safari.self.addEventListener("message", messageCallBack, false); // Message comes from global.html when context menu item is clicked
And the following callback
function messageCallBack(msgEvent) {
...
window.open(...)
...
}
For some reason, the popup works when the button calls window.open, but NOT when the message callback calls window.open. I'm assuming it maybe have something to do with the window object.
I suspect this is due to restrictions on window.open designed to combat pop-up ads. This means it will only work in response to a click event.
To get around this, I would recommend you open the new window from your global page using the safari.application API:
safari.application.openBrowserWindow();
safari.application.activeBrowserWindow.activeTab.url = '...';
You can also open new tabs with:
safari.application.activeBrowserWindow.openTab('foreground').url = '...';
To achieve this, you may need to send a message from your injected script to the global page.

Durandal view no more displayed if user click quickly on menus

I use Durandal 2.0 & Breeze in my SPA.
I have a sidebar menu for my drivers (Chauffeurs) where user can click on submenus (Récents, Disponibles, Indisponibles) for calling my view with different parameters. This will fill a koGrid with data. The data is fetched in the activate call and the binding of the koGrid is done in the compositionComplete.
Everything goes well most of the time. Things goes wrong when I click very quickly on submenus (calling the same view). Example: I click on 'Récents' and immediately (without waiting for the view to display) I click on 'Disponibles'.
I have the following for the activate:
var activate = function (filterParam) {
filter(filterParam);
pagedDataSource.getDataFunction = getData;
pagedDataSource.getPredicatesFunction = getPredicates;
return pagedDataSource.reload();
};
And I have the following code for the compositionComplete:
var compositionComplete = function (view) {
bindEventToList(view, '.kgCellText', gotoDetails);
$('#mySearchGrid').attr('data-bind', 'koGrid: gridOptions');
ko.applyBindings(vm, document.getElementById('mySearchGrid'));
};
When I trace the activity, I noted that if user click quickly on submenus, the activate does not have the time to finish and is called again (for the second click of the user) and the compositionComplete does not execute. Then after that, nothing more happened visually. It seems blocked.
Any idea how can I prevent this problem?
Thanks.
The migration to the latest Durandal version 2.0.1 fixed the problem.