print/print dialog validation by selenium Automation - selenium-webdriver

Has anyone automated validating print/print dialog functionality output anytime?? or if any idea on the same please let me know here.
Thanks in advance.

Your question seems similar to the "File Open Dialog" problem.
My general remark in this case is as follows, when an external dialog (not inside HTML) called by the browser opens, the browser suspends communication with external scripts, including Selenium, until the operation that was called is performed.
In other words, run the AutoIt script first and then call the print dialog, never the other way around.

Related

Packaged shell extension killing application

I have a WPF application. To give it an identity to consume UWP APIs, I've added sparse package support. This installs / uninstalls / updates (we're not using MSIX) with my WPF application fine, and my app is running with an identity. It shows in task manager with a Package Name listed on my process.
Now I'm attempting to add context menu support following Microsoft's docs.
I've created a shell extension which will show when opening the context menu for any file and folder, which is pretty much a copy of their sample with different GetIcon(), GetTitle() and Invoke() implementations for IExplorerCommand.
I'm specifying this in the AppxManifest.xml (values anonymised):
<desktop4:Extension Category="windows.fileExplorerContextMenus">
<desktop4:FileExplorerContextMenus>
<desktop5:ItemType Type="*">
<desktop5:Verb Id="MyFileCommand" Clsid="file-guid"/>
</desktop5:ItemType>
<desktop5:ItemType Type="Directory">
<desktop5:Verb Id="MyFolderCommand" Clsid="folder-guid"/>
</desktop5:ItemType>
</desktop4:FileExplorerContextMenus>
</desktop4:Extension>
<com:Extension Category="windows.comServer">
<com:ComServer>
<com:SurrogateServer DisplayName="SSVerbHandler">
<com:Class Id="file-guid" Path="my-shell-extension.dll" ThreadingModel="STA"/>
</com:SurrogateServer>
<com:SurrogateServer DisplayName="SSVerbHandler">
<com:Class Id="folder-guid" Path="my-shell-extension.dll" ThreadingModel="STA"/>
</com:SurrogateServer>
</com:ComServer>
</com:Extension>
This works, my context menu entry is listed and performs the action as expected. But here's the issue: each time the context menu is opened for the first time, it kills the already running instance of my WPF application. By first time, I mean restarting explorer.exe and right clicking on a file or folder.
My gut feeling is this is related to UWP side of things. This is because originally it would always kill my application when right clicking to open a context menu. But with a little trial and error I solved this by configuring multi-instance support in my AppxManifest.xml:
<Package
...
xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
xmlns:iot2="http://schemas.microsoft.com/appx/manifest/iot/windows10/2"
IgnorableNamespaces="uap mp desktop4 iot2">
...
<Applications>
<Application Id="App"
...
desktop4:SupportsMultipleInstances="true"
iot2:SupportsMultipleInstances="true">
...
</Application>
</Applications>
...
</Package>
I'm hoping someone can suggest any troubleshooting ideas as I'm now struggling.
I've sprinkled some ol' trusty MessageBox functions within the shell extension in DllMain, DllCanUnloadNow and DllGetClassObject. But for that first load attempt, no message boxes are shown, no context menu item listed and my application is still killed.
I've poked around in the event viewer hoping to see any errors or warnings listed recently, plus in Applications and Service Logs\Microsoft\Windows\Appx* and Applications and Service Logs\Microsoft\Windows\AppModel-Runtime. Nothing has jumped out at me.
According to this SO anwser, if there's an error with the shell extension itself, it may not show. That does fit, but I'm sceptical as it always works on subsequent attempts, and the previously solved UWP killing issue.
In the scenario where my application stops, using these powershell commands I get:
$process = Start-Process .\MyApp.exe -PassThru -Wait
$process.ExitCode
1
I do have crash logging in my app, but nothing gets logged. This is the only place Environment.Exit(1) is called within the WPF application.
I did try the silent monitoring detection in GFlags on the WPF application, but couldn't seem to trigger it. Only when I manually closed the application. (Ignore Self Exits unchecked for testing). I'm not sure if that's because the exit code is 1.
When the error occurs with process monitor running, I can see lots of ThreadExit before a final ProcessExit with the exit code 1. That would imply it's exiting cleanly with my application itself returning 1?
It's also worth mentioning I've lived in managed / .NET land for the last decade or so, I don't have much experience with C++ (or unmanaged languages in general) or UWP, and the first time I've attempted to write a shell extension.

GTK+ opening link in about dialog fails on Windows

I am writing a C/GTK+ application and this should be targeted for both Linux and Windows.
I have encountered a problem when I open the website link in the about dialog: the expected behaviour would be the browser to open and show the relative webpage (and this works correctly on Linux), but right after clicking on it a popup comes up displaying "It's impossible to show the link because no application to handle it is installed" (roughly translated, I don't see it in english, but in my native language).
How could I fix this? I thought to set a specific handler for the link only for Windows, but I don't know how to get the "link" object in the about dialog. The only thing I found in the documentation is gtk_about_dialog_get_website_label, but it returns a string, so I don't think the handler would work.
When the website label is clicked in a GtkAboutDialog object, the default behavior is to invoke gtk_show_uri. The latter uses GIO to handle the uri itself, which only handles local files. If you want to handle urls (http[s]://, or ftp[s]:// and such), you'll have to install gvfs.
An alternative approach is to connect a callback to the activate-link signal which is emitted when a uri is activated. You can then handle the event, and work some magic depending on what system your application is running on.
The links from my comment that back my claims up (and are useful references in general) are:
GtkAboutDialog and its signals
gtk_show_uri and other file-system goodies

multiple run and automatic response for each run in batch file

I am creating a batch file to run a software several times. Each time the software is executed, a window with two choices will appear, and the default is just clicking enter. I don't want to click enter for each run, so I would like to write an automatic answer in my batch file. Is it possible?
The basic answer to your question is no.
However, with the help of the software you are launching, or an external tool, you might be able to achieve this.
If this other software accepts parameters, then maybe it provides one to automatically answer that first dialog that pops up.
Otherwise, you can use tools such as AutoIt to simulate a user click in the dialog.
Piping a carriage return works for some programs - that technique depends on the tool.
So see if this works for your program.
echo.|"c:\folder\filename.exe"

How to download any file using selenium webdriver.

How to download any file using selenium webdriver.what is the logic to download any file in selenium webdriver
If you mean "any" file that browser would show, i.e. any html file, you just need to call
driver.getPageSource();
If you mean "any" file as in the "save link as" or similar menu of browsers you are out of luck, since this triggers the OS-driven download file chooser of a browser which can't be controlled by Selenium webdriver.
Solution to 2.
You have two options here I think:
a) use something like AutoIT ontop of selenium. This becomes very hard to control in a short time, is not portable and will make your tests error prone.
b) The better solution is probably to download the file outside of selenium. I found a nice article describing the whole dilemma here. It also contains a nice solution to the problem that takes even care of cookie-handling if needed for the download.
Actually it's not a good idea to download files using web-driver. I don't think that you need the file; in most cases, it's just for testing download links and for this purpose you can use driver.find_element_by_tag_name("a"), driver.find_elements_by_link_text("some text") or driver.find_elements_by_partial_link_text("a"); after finding the element, you just click() on it and check if the response's URL is actually what it should be.
Still if you have a goal for completely downloading the file, I'd be glad if you let me know.
EDIT:
Today, I visit this page and I think this will help you, specially this comment.

Win32 disabling windows modal error dialogues when copying files

I am working at an OS independent file manager (using SDL). I am trying to use native functions as much as possible (with the appropriate #ifdefs), and I am having a problem with Windows. When I am using
CopyFileEx()
for example, if there is a problem it will pop up a modal dialogue, and the user will have to press some buttons to get rid of it. I want to handle the errors myself, in my programs, to make it less annoying.
Is there any way to disable those modal windows?
I noticed that if I start my application from a debugger (Insight) it will not display those messages.
Thanks in advance!
P.S. The language I am using is plain C.
You might want the SetErrorMode function.
For a Windows file manager SHFileOperation() is possible a better fit than CopyFileEx(). This will result in the native sheall dialogs for progress, conflict resolution etc. The levels of progress and error reporting can all be controlled.

Resources