How to handle popup messages thrown from web applications in vb.net? - vb.net

I am developing a tool to automate testing of a web application. I want to handle the popup messages thrown in error scenarios. The problem am facing is after a button click a popup message is thrown, but only after a response is given to the message box(ie clicking on any buttons in the message box) the execution continues, till then the web browser is busy waiting for a response. Please suggest.

You could have your application inject some javascript into the page that overrides the default alert/confirm function. This would allow you to run code before the alert is shown or completely override the functionality so that the alert isn't shown at all.
See this custom alert demonstration for an easy example of how to override the default alert function.

Related

Insight tool shows error icon, but shows message "No failure was detected"

I am using a tool for verifying if app is compliant with windows accessibility feature
Tool web link - https://accessibilityinsights.io/downloads/
Test tool have simple MFC combo box .
Tool says "No Failure was detected",
Insight tool shows a error icon.
Below are steps to get above state.
Launch app
Launch Insight tool
select what to test = element
Mouse hover on combo box
expand the combobox
mouse hover on item
click on brush icon on right
It will enter the state described abovewith no error but with error icon
Isolation:
Issue doesn't repro when "Entire App" is selected.
When "Entire App" is selected, tool does not show any error or any error icon. App pass accessiblity
Question is if this tool is reporting valid error ?
What is the error as tool says " No failure was detected."
What you're seeing here is an artifact of trying to capture a transient state. Combobox content goes away when the combobox closes, and that happens as soon as you start the scan. Accessibility Insights for Windows allows you to trigger a scan using a timer, as documented at https://accessibilityinsights.io/docs/windows/getstarted/automatedchecks/#running-automated-checks-with-a-timer. The "short version" is that you start the timer, then open the combobox while the timer is counting down, and the checks will run when the timer reaches zero. The combobox will still be fully opened at this point, so the tests will apply to the combobox contents.
My personal recommendation is to set the scope to the entire application when using the timer, just because transient controls sometimes have multiple layers and trying to have the scope of just the element can tend to hide children of the layers in question.
Thanks for using Accessibility Insights
--DaveTryon
Accessibility Insights team

Halt code at dialog (msgbox()) command in IDE

Title quite much says it all.
In VB6, and in VBA/Access it was possible to hit break key, and jump into debug mode when using the msgbox() command.
Is there a way to do this in vb.net (desktop/winforms) applications?
Often, some code will toss up a dialog box, and it is rather nice then to jump into debug mode as a result of that message box having been displayed.
Edit
Ok, hitting pause button in most applications work, but in this application, when I hit pause, then I get this:
Edit two:
Ok, I have discovered the reason for this behavior. I have the application Frame work box un-checked. The reason for this is I did't want to specify the main application form as startup form, and I desired additional control over what occurs if the main startup form (that I don't specify) is closed. Thus, my main application form is launched via application.Run(my form)
It thus seems that due to starting the main form as a new separate application thread (which is the result of using application.Run(), then you can't use ctrl-break, or more common use/hit the pause button in the IDE to halt the code. Hitting pause will thus display that the application is running a main app thread, which indeed is the case since I use applicaiton.Run() to launch the main form from the classic and traditional Sub Main().
Edit 3
A way to fix this, and enable the pause key to work is to un-check in tools->debugging the [ ] Enable Just My Code. This will thus allow debug mode of the other "main" application thread.
Hmm. [CTRL][BREAK] clears the dialog box. However, clicking the pause button in the IDE will do what you want.
Alternatively, select Debug > Break All from the menu.

How-To: Handel standard Closing dialog of onbeforeunload in Firefox with Selenium

I have to test a web-application with Selenium (actually I'm using it in Java).
there is an confirmation Dialog on leaving the page and I need to handle it in Selenium, the 1. confirmation box i can handle easily, but Firefox throws out and 2 confirmation box with standard message and I don't know how to turn it of or handle it with Selenium.
window.onbeforeunload = onEditorClose;
function onEditorClose() {
msg = "Möchten Sie den Editor schließen?";
return confirm(msg);
}
I have some possible Solutions like, deleting the 1. confirmation and only having the standard message but even there is the problem, Selenium seems not to be able to handle the standard dialog :O.
Can anyone help me here?
I easily solved the Problem, I just overwritten the function with selenium.runScript();
selenium.runScript("window.onbeforeunload = null;");
so when before the window gets closed the onbeforeunload is seted to null and nothing will happen, while closing :P.
for me its OK, cause i don't need to test the onbeforeload.

Modal dialog present (WARNING: The server did not provide any stacktrace information)

I currently using Selenium Web driver.(2.24.1)- Programming Language--JAVA
I want to save a web Page in HTML only Format, so i am using Robot class to save webpage.
I am using this Save functionality in a loop (for n times).
This is working good for for few cases in the loop but randomly( may be 1st time or 3rd times...nth times) it fails with an error message "Exception in thread "main" org.openqa.selenium.UnhandledAlertException: Modal dialog present (WARNING: The server did not provide any stacktrace information)"
Well it depends on what the Modal Dialog was, but there are three things I would check.
First Most likely you'll need to upgrade your Web Driver
I noticed you're using Webdriver 2.2.24, if you're also using FireFox as the browser you'll want to upgrade your WebDriver to 2.2.26 or higher. There was a change to "Prevent firefox from updating, checking and warning for extension and plugin updates" IF any of those things occur they also will raise a modal dialog.
Second It could be a dialog raised by the site you're testing
javascript alert() or a window.Prompt() are examples of modal dialogs the site be raising to do any number of things. You can use the WebDriver to interact with these dialogs.
Third If it's none of the above get a screen capture of the dialog
The dialog may not be something that you can access through the WebDriver API so you need to write code to get capture the entire screen (should be easy with some googling). Or you can record a video session when running the code.

Selenium RC - selenium-browserbot.js error

I'm writing some automated tests in C# and a JavaScript error is thrown when I try to click on a button that will submit changes made to a web form. The error I am recieving is:
An error has occured in the script on this page
Line: 2004
Char: 9
Error: Permission denied
Code: 0
URL: file:///C:/DOCUME~1/nkinney/LOCALS~1/Temp/customProfileDir6c0c7d7226cc463fb­b1a7f6253c4df62/core/scripts/selenium-browserbot.js
Once the test is finished, the error will still be displayed if I manually click on the button while selenium is running.
The line in selenium to select this button is:
selenium.Click("//input[contains(#id, 'SubmitBtn')]");
I've also tried submit.
A pop-up should be displayed asking the user to confirm they want to make the changes. This error is thrown before the pop-up is displayed and after Selenium 'clicks' on the button.
Any advise would be greatly appreciated.
After further investigation, I found that Selenium is unable to work with custom modal dialog boxes. That said, I don't think I will be able to use Selenium to automate UI testing in our current release. Thanks to anyone who looked at this post.
From the Selenium FAQ
I can't interact with a popup dialog. My test stops in its tracks!
You can, but only if the dialog is an alert or confirmation dialog.
Other special dialogs can't be dismissed by javascript, and thus
currently cannot be interacted with. These include the "Save File",
"Remember this Password" (Firefox), and modal (IE) dialogs. When they
appear, Selenium can only wring its hands in despair.
To solve this issue, you may use a workaround (if one exists);
otherwise you may have to exclude the test from your automated corpus.
For the "Save File" dialog in Firefox, a custom template may be
specified when running via the RC that will always cause the file to
be downloaded to a specified location, without querying the user (see
http://forums.openqa.org/thread.jspa?messageID=31350). The "Remember
this Password" dialog should not appear again after you've chosen to
remember it. Currently there is not much that can be done about IE
modal dialogs.
Do you have the option of seeing if the test runs in another browser (Firefox, Chrome)?
A very similar answer is also here: How do I test modal dialogs with Selenium?