Could not get Alert dialog with Firefox when using final WatiN version - firefox

The code below works well with IE7, but when I switch to run with Firefox (from 3.0 to 3.6) I could not get the the Dialog. It raise error on line: DiaglogHandler.WaitUntilExists(10) "Dialog not available within 10 seconds." even though the dialog is there. I'm using the final WatiN release.
string url = "https://www.xxx.com"
Settings.AutoStartDialogWatcher = true;
Settings.AutoCloseDialogs = false;
//var browser = new IE();
var browser = new FireFox();
browser.GoTo(url);
Image theButton = browser.Image(Find.By("id", "button"));
AlertDialogHandler DiaglogHandler = new AlertDialogHandler();
DialogWatcher theDialogWatcher = new DialogWatcher(new WatiN.Core.Native.Windows.Window(browser.hWnd));
theDialogWatcher.Add(DiaglogHandler);
theDialogWatcher.CloseUnhandledDialogs = false;
theButton.ClickNoWait();
DiaglogHandler.WaitUntilExists(10);
Console.WriteLine(DiaglogHandler.Message);
Console.WriteLine("Done");
Console.ReadLine();

Afaik WatiN does not deal well with Dialogs yet, though it is on the horizon.
It is possible to get around them, say passing an Enter to the browser or other javascript interaction.
I've had similar issues with Authentication Required Dialogs in FireFox

Related

How to redirect to another page from within Xamarin Webviews Navigating event

I want to do a very simple thing: if a person goes to a specific page within my webview I want them to be redirected to a different page. I want to do this to prevent an errorpage from showing on session timeout. So this needs to happen from within Xamarin because I have to resend the user credentials.
To do that, I believe I have to catch the Navigating event, check if the webpage corresponds with the page I don't want to see. Cancel the Navigating event and set the browser URL to the page I want to redirect to.
private void Navigating(object sender, WebNavigatingEventArgs e)
{
String url = e.Url;
if (url.Contains("unauthenticated.xhtml"))
{
url = getURL();
e.Cancel = true;
browser.Source = url;
} else
{
e.Cancel = false;
}
LogService.log("navigating to " + url);
}
This doesn't work. I still get to see the ugly unauthenticated.xhtml page and no redirect. If I debug I run through the code correctly so I know the event is always caught well and the check for the website works. If I got to the new url in the browser the correct page is displayed.
Now, if I remove this line
e.Cancel = true;
I get closer to the result I want. Then I do get redirected to unauthenticated.xhtml, but within a second I am redirected again towards the correct page. So the warning flashes on the screen and disappears. (Makes sense: both Navigation events still go through)
I have also tried placing these two lines in this order:
browser.Source = url;
e.Cancel = true;
But the result didn't change.
How can I get a well working redirection from within the program?
Thank you for your help.

Firefox add-on triggers code in each open window

I have a Firefox add on that displays a pop-up when it sees a certain response header. This works fine when I have a single window. However, when I have multiple windows open, and one of the tabs in a window triggers the pop-up code in my add-on (due to the presence of said header) I get a pop-up in each of my open windows. For example, if I have 3 windows open, I get 3 different pop ups, one for each windows. Is this the default behavior, and is there an easy in-built way to fix this using their SDK.
Edit:
I have the following code:
Util.requestBlock(httpChannel) {
/*load response headers here*/
if (responseHeaders.includes("header_xyz"))
alert("show popup");
}
Util.monitor = function(w) {
this.obsService = Components.classes['#mozilla.org/observer-service;1'].getService(Components.interfaces.nsIObserverService);
this.obsService.addObserver(this, 'http-on-examine-response', false);
}
Util.monitor.prototype = {
'observe': function(subject, topic, data). {
if (topic == 'http-on-examine-response'). {
var channel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);
var block_response = new Util.RequestBlock(channel);
}
},
};
The Util.monitor adds an observer. Whenever a response is received, the "Observe" function is called.
var windows = require("window-utils");
for (window in windows.browserWindowIterator)
doToWindow(window);

Showing Base64String as Image works in IE but not in Chrome

C# code:
public ActionResult GetDoucmentImage(long onBaseDocumentId)
{
onBaseDocumentId = 1111;
OnBaseDataAccess db = new OnBaseDataAccess();
OnBaseDocument document = db.GetDocument(onBaseDocumentId);
return View("GetDoucmentImage", document);
}
View Code:
#{
var base64 = Convert.ToBase64String(Model.Data);
var imgSrc = String.Format("data:image/png;base64,{0}", base64);}
<img src="#imgSrc" style="width:200px; height:400px;"/>
Trying to show an image in browser, it works in IE but not in chrome
using chromium, select your image element and right click and select the "Inspect Element" from the context menu....
the chromium Developer tool will open and highlight the client source of the image element....
compare the src value with that shown in the IE Developer tool (f12>Find tab)....
I think MSIE and Gecko browsers sanitise base64 encodings (toStaticHTML), to prevent malicious script injections...
Maybe your Model.Data is not actually a png image.

Firefox crashes on element.remove()

When tinyMCE is used with Firefox and the user drags an image into the editor,image.remove (); window FF converts the image to a base64 string and embeds the image as text--not optimal DB strategy. This question addresses the issue. I've added a simple handler to the editor that handles it simply:
if (tinymce.isGecko) {
editor.getDoc().addEventListener('DOMNodeInserted', function(event) {
var image = event.target;
if ((image.nodeName === 'IMG') && (image.src.substring(0, 30).match(/.*?data.*?;base64/g))) {
image.remove ();
alert('Using drag-and-drop for images with Firefox has been disabled for technical reasons. Please use the "Add Media" button.')
}
},
false);
}
But image.remove (); crashes Firefox every time. Can anyone verify this, and is there a workaround?

detect new browser window with WATIN

is there a way to test wether a link was opened in a new browser-window (or browser-tab)?
Update:
So far I used the following code:
var newBrowserWindow = Browser.AttachTo<IE>(Find.ByTitle(browserTitle));
Assert.That(newBrowserWindow.hWnd, Is.Not.EqualTo(existingBrowserWindow.hWnd));
Where I used the existingBrowserWindow to open a page and to click on a link. But when the link opens a new tab in the existing browser (default behaviour for IE with targer=_blank) it has the same window-handle, since it's the same browser window. So how can I detect a new tab?
Some code of yours would help...,
Anyway, what I do when a link open a new browser window is
using (var newBrowser = WatiN.Core.Browser.AttachTo<IE>(Find.ByTitle("Analytics - Read conversation"))
{
}
Browser.AttachTo supports Find.ByUri(), Find.ByTitle() and Find.By("hwnd", windowHandle) according to documentation. I only tested Find.ByUri() and Find.ByTitle() methods.
if you want to detect if you action has opened a new window you could do
public bool TryGetNewBrowser(out IE browser, string title)
{
try
{
browser = WatiN.Core.Browser.AttachTo<IE>(Find.ByTitle(title));
return true;
}
catch(WatiN.Core.Exceptions.BrowserNotFoundException)
{
browser = null;
return false;
}
}
As far as I know, there is no support in WatiN for new tab. But the default behavior of internet explorer is to open new links in new window.

Resources