How to track closing of browser process opened via winform application? - winforms

I have winform application and I am opening browser process with some url.
I want to update data on winform application on close of opened browser window.
I tried process.hasExited, but its not working.
Also I am not able to find processid of browser processs in Process.getProcesses.

Related

Winappdriver and selenium in the same automated test

Hi I could do with some help / more experienced eyes.
I have a WPF application which I have started automating some UI tests for using winappdriver, upon further investigation it has embeded html in it - webview, and can fire off requests to open the default browser with app related content - such as help files.
Has anyone had experience in working with this? For example:
open the WPF app,
click on help button on the WPF app which will open a browser and
then continue the test to ensure that the correct help page has been launched with the correct content in relation to the WPF page it was fired from.
Presumably this can be done in my case with chrome driver (winappdriver cannot see the content on the webpage). I have tried using selenium's window handles, but it's like the driver can't see the already open browser page. So I am at a bit of a loss and really not sure what to do.
In previous roles I was used to using Ranorex, which does both windows and web based UI automation. So I have never had any experience using multiple driver types to do the one test.

.NET Windows Form - Interact with a website's filedialog opened from webview2

I'm using webview2 in a .NET Framework Windows Forms application to automatically upload files to a website. The site only supports uploading one file at a time and we often have to upload hundreds of files. I used java script in the webview2 to execute the steps for the upload.
My problem is that to specify the file to upload I have to interact with a file dialog box that's opens on a button click from the website within the webview. I'm currently populating the path of the file to upload in the filedialog using SendKeys, which I think is a poor process.
Is there a way that I can interact with the filedialog that is created from the website through my Windows Forms application? If so how would I get started in figuring out how to do that?
Here's more detail on what I'm currently doing:
In the webview, to begin an upload you have to click a few checkboxes to choose upload options, which has to be done every time, so I run these commands first:
await webview2.ExecuteScriptAsync($"document.getElementById('SelectedTypeId').click();");
await webview2.ExecuteScriptAsync($"document.getElementById('AutoAcceptChkbox').click();");
Then, there's a command to click an upload button, which opens a file dialog:
await webview2.ExecuteScriptAsync($"document.getElementById('uploadFile').click();");
From here, I get the filedialog and use SendKeys.Send("Filepath to file") and SendKeys.Send("{ENTER}") to populate the file path and select the file.
Once the filedialog closes I have an additonal command to click the import button to begin the import.
The issue I have is with the filedialog. It's obviously not a great process to use SendKeys to populate the path to the file. Also, I have to make the application "wait" around the sendkeys actions so that the filedialog has time to come up and close out before moving forward, I'm betting at some point there will be errors if the application isn't waiting long enough.

How to close React.js PWA to apply updates?

We are developing a React.js PWA.Is it possible to programmatically close application after gets update to apply them?And how?Is there another solution for it??
You can not close the application, you are not allowed to close the tab opened by the user. Only tabs that have been opened with a code can be closed with a code.
This is your problem with killing Application in RAM(app cleaner).
This will clear the cache of the previous version of the application and replace it with the new main.chunk.js.
I have a solution that you can update the program without closing it, for doing this you can use the "clear-cache" React library.
close application after gets update to apply them
This in case of a web application would be killing the caches and refreshing the browser tab.
You can kill caches by applying something like versoning/time stamps/unique id etc to the resource URLs, so that on refresh browser detects them as a new resource that needs to be downloaded.
You can force refresh the app using location.reload();

Selenium IE webdriver - how to cope when the application closes the browser window and launches a new one?

I have an instance where user try to log-in application (simple webpage). After successful log in, the application closes the current page and open a new webpage. Rest of the business operations start from there.
Till the point API clicks log-in button, everything goes fine. After log in (once the log in webpage closes and a new session gets opened), the API throws "Unable to find browser". This is true as the original driver instance has been closed by the application.
Is there a way to achieve these kind of scenarios using selenium, as they are very common now-a days in a typical business application.
Thanks.
If you need to driver a different browser window or iframe, you need to use switchto. From the WebDriver faq:
Q: How do I handle pop up windows?
A: WebDriver offers the ability to cope with multiple windows. This is done by using the "WebDriver.switchTo().window()" method to switch to a window with a known name. If the name is not known, you can use "WebDriver.getWindowHandles()" to obtain a list of known windows. You may pass the handle to "switchTo().window()".
Thanks for the Answer.
I did the below to achieve my query.
Execute a javascript to open a new window.
IJavaScriptExecutor jScript = driver as IJavaScriptExecutor;
jScript.ExecuteScript("window.open()");
Switch to the newly opened window.
List<string> handles = driver.WindowHandles.ToList<string>();
driver.SwitchTo().Window(handles.Last());
Start the Navigate and Login operation on the new window
driver.Navigate().GoToUrl("Your website");
After login, the application will close the new window but the main driver window will still be alive.
Implement a simple SwitchTo() for the new window to start new business operations
List<string> handles = driver.WindowHandles.ToList<string>();
driver.SwitchTo().Window(handles.Last());

Access Silverlight window within Chrome via System.Windows.Automation

This is probably futile, but I'm wondering if anyone out there has experience doing this.
I'm trying to access a Silverlight application hosted within Google Chrome by using System.Windows.Automation (e.g., AutomationElement).
The problem I'm having is that Chrome hosts the Silverlight app within a child process. If I attempt to find the "Silverlight Control" AutomationElement (by using the main process' hWnd), it fails.
If I locate the Silverlight host child process, it does not have a window handle, and if I attempt to find the control using the child process' Handle it fails.
I know it's there... I can see it using Inspect
but I can only find this by clicking in the Silverlight app and navigating up in Inspect. I cannot navigate down from the tab window using AutomationElement.FindFirst or Inspect.
Its like there is a disconnect between the window and the Silverlight plugin that isn't seen in IE or Firefox, and I don't know how to get around it.
Has anybody else been able to do this?
I'm not sure if this helps or not in your instance but I've run into a couple instances where I needed to enable communication into Silverlight from outside (Office Application AddIns that need to communicate with the Silverlight Application). I've used javascript in the html page hosting the Silverlight Application as a bridge for that communication:
function sendToNav(message) {
var nav = document.getElementById("Nav");
nav.content.NavigationPage.HandleScriptedMessage(message);
}
function passMessageToHost(message) {
if (window.external == null) return;
window.external.HandleScriptedMessage(message);
}
If there any additional information I can provide please let me know. Hope this is of some use to you.

Resources