Chrome WebDriver does not open when called from IIS - c#

I have a really strange issue (And I have a really strong suspicion - that it will be on the IIS side).
I have .NETCORE6 application, which uses Selenium via IHostedService.
There are cases that work:
If I launch the application from Visual Studio's IIS locally the browser is opened
If I launch the application from CMD (as self-hosted) the browser is opened
If I launch the application from CMD (as self-hosted) on the server the browser is opened
BUT
If I launch the application from IIS on the server - the tests are running (looks like in headless mode) but the browser is not shown.
Does anybody have experience with IIS?
I have tried different IIS Pool Identity - and executed the app as a DefaulPoolIdentity, LocalService, LocalSystem, and even as my user which has admin rights - but the browser is still hidden.
Additional Notes:
I also checked - that the browser is launching in maximized mode and on the correct screen
So the question is how to launch the app from the server via IIS with the web browser opened? (There just must be the solution for that right?)

Lex Li's answer is the correct one - so if anyone else finds the answer please read the article https://blog.lextudio.com/web-application-differences-in-visual-studio-and-iis-60fec7e311b3

It seems that if you start chromedriver manually and then call it using Selenium Grid the browser will open.
Driver configuration would be something like
var uri = new Uri("http://localhost:9515/"); --my chromedriver uri
var driver = new RemoteWebDriver(uri, new ChromeOptions());
...

Related

Creating a web scraping program compatible with Windows task scheduler "run whether user is logged on or not"

I need to be able to web scrape information daily on a website that requires login credentials. I have wrote a program in C# that uses Selenium and Chrome, which works well when run normally, or through the Windows Task Scheduler when selecting "run only when user is logged on". However, Chromedriver.exe stalls when selecting "run whether user is logged on or not", presumably because this option forces chrome to run in the background and thus my program is not able to enter in any login credentials. I need to be able to run this program whether the user is logged on or not, because it is on a server where multiple users may be accessing it at a time.
I have tried wrapping the execution of the .exe within a batch file and using different web browsers (firefox/Chrome).
I am looking for
any solutions to make a Selenium app work as a background process with the Task Scheduler option "run whether user is logged on or not"
or
a framework other than Selenium with which I can automate entering text and clicking, and which can work in the non-interactive mode that is launched through the windows Task Scheduler.
Thanks for reading my question.
It seems that you are looking to use "headless chrome". According to Getting Started with Headless Chrome:
A headless browser is a great tool for automated testing and server
environments where you don't need a visible UI shell.
Look at the following chrome switches (options):
--headless (or "headless")
--disable-gpu
Here's are a couple of resources for chrome switches (options):
List of Chromium Command Line Switches
Chrome switches
According to the ChromeOptions Class documentation, you should be able to do the following:
ChromeOptions options = new ChromeOptions();
For use with ChromeDriver:
ChromeDriver driver = new ChromeDriver(options);
The following post may be helpful: How to start ChromeDriver in headless mode

When I launch an asp.net application, IIS Express launches duplicates of running sites

When I start my asp.net application in debug mode, IIS Express launches two instances of each endpoint. This does not allow the site to start fully.
How do I solve this?
About the "duplicates"; If you look at the endpoints in your picture, you see that one is for http and one is for https. This is as expected.
I can also see that you are trying to open the https version (on port 44300) without specifying https://
Try opening http://localhost:8765 or https://localhost:44300

C# process.start not working on iis

I'm trying to run an exe with parameters from a web application.
I'm using Process.start() but it does not seem to run on iis!
It works fine when running from iis express. I'm publishing the application to my local iis as a test but it does nothing.
I've tried setting the iis admin service to enable interactions with the desktop and ive told iis to connect as my user credentials and set the application pool to use the same user credentials but still nothing works!
is there anything else someone can advise to get this working!
Cheers.
UPDATE
I got iis to run the process by setting the application pool identity to local system and double checking the credentials for the site.
But as expected the applications do not interact with the desktop, so creating a file from command line is simple, but running an application with parameters do not have the application open.
At the moment iis admin service has interact with desktop checked and is using the local system account.
Ok so this isn't really an answer but in the end I got process.start to work by setting the application pool identity to local system.
But as expected the commands do not interact with the desktop, but this was enough for what my application needs to do.
Sorry for the poor answer.

automated task with selenium on a website

I have an application that is accessed by many users. It's a .net 4.0 C# web forms application, and they requested me to automate a task that they have to do almost daily. The task I should automate is to access a link outside my domain and fill it up with some info, log-in, and other stuff like dates.
So, after many researching and reading, I've managed to do it locally with Selenium. I have the entire process automated and I call it from a link inside my website. Locally it works like a charm.
Here's the code:
public void AutomateTask()
{
var url = new Uri("http://127.0.0.1:4545/wd/hub");
var capability = DesiredCapabilities.Chrome();
var driver = new RemoteWebDriver(url, capability);
driver.Navigate().GoToUrl("url");
//do all the stuff I need to do
driver.Close();
}
I start my server using this command:
java -jar C:\...\selenium-server-standalone-2.43.1.jar -role hub -port 4545
The main problem is that I have to publish my website for the users and they should be able to use the automated process without having to start a selenium node on their machines or anything else. Locally I have a node running for each browser, is it possible for them to consume this webdrivers? I mean, users should not worry about installing or anything, they should just click the link and see their browsers acting till the task is over. When I click at the link on my application(from my local IIS) on another computer, a new window of the request browser is opened on server machine, not on the machine which clicked the link.
I've looking everywhere for a solution for this but none was found.
So:
I have a website that access a third website.
I need to automate this process.
Users must only click the link, wait the new browser window open, wait for some fields to be filled automatic and then fill the captcha and press "continue", then enjoy their browser working.
Is it possible with selenium? If not, which framework or how can I achieve this?
Let me know if any further details are required.
If you don't need to show the browser to the users you could just put a link on your webapp which runs selenium on the machine hosting your webapp. That way you only need to have selenium installed and running on the webserver hosting your webapp and not all the end user machines. If you do it this way you should probably use the HtmlUnitDriver because its headless and you really aren't going to be watching these selenium tests executing.

IIS Session isolation problem

I am using ShDocVW.InternetExplorer class to spawn a new internet explorer object and to do some form filling stuffs(for some sharepoint works).It works fine in my own machine which has Windows 7 as the OS. But when I deployed the same thing in windows server 2003 machine, it does not pop up the internet explorer window. When I check the Task Manager, I could see a new iexplore process, but with Session ID = 0 (but session ID = 1 in windows 7). So, I see this is something regarding IIS Session isolation.So, is it possible to assign a ShDocVW.InternetExplorer instance to kind of a new System.Diagnostics.Process and achieve this task? Or can we start a new ShDocVW.InternetExplorer instance with session ID = 1?
thanks in advance.
I'm not very clear on what you are doing but if the app that spawns the ShDocVW.InternetExplorer process is an ASP.NET app then you won't see the window because IIS runs as a windows service and as such Windows Services use a different "desktop" than the desktop you're logged in as. So you'll never see any windows and Windows service application launches.
I think what you should do is create a GUI applications that instantiates your explorer window.
Basically the problem is that you are trying to do something through code, and since this will work on the server you will see a process getting spawned on the server... AND NOT on the client as you are assuming. It is working on your dev machine, since you would have been using FileSystem for your project and your project's pages are being served by cassini - Web Development Server which launches on your own machine.
The approach of filling out the form is wrong. You should be using POST request and read the values on the server for doing necessary processing of the data that has been posted.
Yap... I got the answer to the problem, In IIS we cannot spawn processes using Shell Execution with the default settings... If we need to do so, there are 2 workarounds that need to be set which can be found from here. And by the way, thanx very much for you guys' input and support which helps me to figure this out. cheers...

Categories

Resources