Cannot upload file to D365 in headless mode Selenium C# - c#

I have a set of Dynamics 365 automated tests which run fine whilst the browser window is open on the screen, but when I run the tests in headless mode, all of them fail when trying to upload a document.
This is my current code for uploading the file:
PaperClipButton().Click(); // this clicks the paperclip icon to open the file upload window
Driver.SwitchTo().ActiveElement();
SendKeys.SendWait(#$"{rootDirectory}\MyFile.pdf");
SendKeys.SendWait(#"{Enter}");
When running in headless mode it inputs the string that is supposed to go into the file upload window inside the Visual Studio window when I'm debugging the test and not in the browser where it's supposed to go.
I've checked the failure screenshot and it doesn't open the file upload window at all and fails on the step where it checks the file has been uploaded.
Also tried removing the line for SwitchTo().ActiveElement() but get the same result
Has anyone had similar issues with D365 automation?
Thanks in advance

I recommend to put the file in your solution and do paperclipElement.sendKeys the path.
Once you click on paperclip, I am guessing file explorer will open up, Selenium cannot control OS applications.

Related

ClickOnce deployment: Why is there a 404 error on a URL which, if pasted into the browser, has no problems?

I've published a half dozen apps written in C# using Visual Studio and ClickOnce to IIS running on my development PC but with one solution, which has a VB.NET main project and C# class library, I'm getting an error message: Invalid URI: The hostname could not be parsed.
The app is being launched via the launch link in the publish.htm file. Edge asks if I want to open it. I click the OPEN button and the app is downloaded and the progress bar finishes and then there's the popup error message saying that the URL could not be parsed.
When I check the IIS logs it looks like this:
https://mypc/apps/foo/publish.htm 404 0 2 1
But if I paste the URL https://mypc/apps/foo/publish.htm into the Edge browser's address box, the page is opened in the browser without any issue:
So I don't understand the 404 error. The other apps, all of which can be launched without issue from their publish.htm page, are published in identical manner, to the same website location in sibling folders:
https://mypc/apps/foo2/publish.htm
The structural differences between this solution and the others are
the EXE project of this problem solution is written in VB.NET and there is another project in the solution written in C# that produces a class library and
in the problem solution on the EXE's Properties->Application tab, there are two buttons: Assembly Information and View Windows Settings whereas on all the other working apps there is no View Windows Settings button on that tab and
on the working applications there is a Manifest option on the Application tab, where one of the choices is "embed manifest with default settings" whereas on the VB project's Application tab there is no such Manifest dropdown visible.
I hope there is some clue in these details. What am I missing and how to proceed to troubleshoot this?

Programmatically monitoring which tab is opened in visual studio

Let's start with an example, User have several tabs opened for a solution>project in Visual Studio (Default.aspx, Default.aspx.cs) I programmatically want to monitor devenv.exe process and want to know which tab (file to be exact) user is working on. If there's some log file or process object has some attribute that tells? Or it has to be done with image processing?
You can write an extension for Visual Studio and monitor DTE.Events.WindowEvents.WindowActivated. From an active window you can get Document.FullName for a file user is working on.
See for example Display document path of the active window in the status bar.

Silverlight functionality not working on Mac

I have an application built in silverlight and it has a functionality that uploads an excel file and an image file on individual button clicks.
When I open the app on windows (Internet Explorer, Safari, Chrome) - it works smoothly.
When I open the same application on Mac, this functionality (image and excel upload) fails.
Button_1 to Upload Image - I do get the file dialog box, I select the file, but when I say Ok, I do not get any errors, but the image upload does not work (I do not see the image uploaded)
Button_2 to Upload Excel - I do get the file dialog box, I select the file but when I say Ok (Error message: Excel is already open but I have checked numerous times... Excel is closed)
This error I am getting is only on Mac Machines... On all windows machines, it works smoothly
Silverlight Version - 5.1.302, Mac - 10.7.5, Browser - Safari - 6.1.1
Any clues?
I have found solution for this. We need to make some security changes in the Safari settings. Following are the steps I tried and things working fine. 1. Open Safari
2. Open desired application where you have issue
3. Click Safari from Top Menu Go to Preferences  Security  Internet Plug-ins ( Click on Manage Website Settings )
4. Left Window locate Silverlight and select it.
5. After selecting Silverlight  On right side window  You will see “website you have opened” and a dropdown  From Dropdown  Select  Allow Always and Run in Unsafe Mode
6. You will be prompted with some warning message – so that is ok… Say Ok and then click Done.
Close Safari completely – Make sure Safari browser is closed completely.
Open New Safari browser instance and launch application. Since I am running application in secure network - running application in unsafe mode do not cause any security level issues.

debugging an executable created by application

I'm having a difficult time finding the right keywords to search on for this. I'm simply trying to figure out a way to debug an executable file that was created by my application. I just created an executable file from my application that contains some encrypted stuff which starts my application when double clicked, that my application uses for certain things. Is it possible to run that executable program that starts the application, and debug the entry into visual studio? I need to verify that the encrypted data is decrypted properly in the application, and the only way to verify this is with debug, or writing to an output file the decrypted information. I'd rather just debug, so I don't have to remember to take out the code that produces the outfile.
Thanks in advance!
Make sure that you application is installed with the .PDBs in the directory with it.
In visual studio, load the solution containing your application.
After you have started the app by double clicking on the associated icon select debug| attach to process ...
Select your process.
If you application is going right into action you may have to add a thread.sleep(10000) (or show a modal dialog) to give you time to attach to the start while you debug - remove it when done.

Opening a browser window after a visual studio-created setup file finishes installing

I'm making a setup file (.msi) using a visual studio setup project. Currently, I need to register a component -a BHO- along with the main installation and open a browser window to a site that requires this component in order to work as intended.
So far, I've managed to install the component by registering it with the "vsdrfCOM" option on the component file properties.
As for opening the browser window, I created an installation class which overrides the OnAfterInstall method and creates a browser window, opening it on said site. Then I added this class on my project as an "Install" custom action. Below is the code I'm using.
Process.Start("IExplore.exe", url);
The problem I'm having is that right after the progression bar form, the browser window opened by the setup file doesn't load the BHO. Yet, if I execute IExplorer.exe from anywhere else, even before the browser window shows up via setup, it identifies the BHO just fine. Any ideas of why is this happening?
Thanks in advance.
Override the Commit method.
System.Diagnostics.Process.Start("http://localhost/[your_site]/Default.aspx");
But I don't know how to get [your_site] in Installer.Commit Method.

Categories