0

I am new to Selenium and TFS build. I wrote some UI test cases with Selenium WebDriver, it is running fine in my local environment. Now, I want to run these UI test cases in the TFS build. I did the following to existing build tasks.

  • Added a Visual Studio Test Platform Installer
  • Added a Visual Studio Test task

The vsTest fails on the below line with error: System.Net.WebException : The underlying connection was closed: The connection was closed unexpectedly.

new DriverManager().SetUpDriver(new ChromeConfig());

I found out that the above line of code tries to check the latest version WebDriver and downloads if not exist from https://chromedriver.storage.googleapis.com. However, on the TFS build server external URL are closed and that could be the reason. Still not sure, I am trying to open this Url on the build server.

[Update] I managed to open googleapis.com Url on the TFS build server. Now a sample test to browse microsoft.com is working but tests for my own website (ex: http://domain or localhost/page.aspx) are still failing. Getting the following error:

OpenQA.Selenium.WebDriverException : unknown error: net::ERR_CONNECTION_REFUSED
(Session info: headless chrome=87.0.4280.66)

Just for information, there is no IIS on the TFS build server. Also, this is an Asp.Net WebForms application.

Do I need to host the website/code on IIS or IIS Express? Just wondering without hosting how will test able to browse it? Sorry for these questions, doing it for the first time and don't have much idea, how to setup everything togather.

Note: I want to do this in build and not in release. Is it feasible to do in the build pipeline? or It must have to be done in the release pipeline? I have configured tests for Chrome in headless mode

Mahesh
  • 402
  • 2
  • 5
  • 16

1 Answers1

2

As far as I known, Selenium UI test can be executed in both build and release pipeline.

OpenQA.Selenium.WebDriverException : unknown error: cannot find Chrome binary

The issue seems to be that the chrome driver cannot find the chrome.exe file.

Since you are using the TFS to run the test , you need to make sure that Chrome is installed on the machine where the agent is located. If only the chrome driver is installed, you will face this issue.

If you have install the Chrome, you could check the file path of chrome.exe.

As per the ChromeDriver - Requirements.

enter image description here

On the other hand, this issue may be related to the version of chrome, this is an open ticket with similar issues, you could refer to it.

You could try to run the following script and check if it could work:

npm i chromedriver --chromedriver_version=LATEST --save-dev
Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • Thank you for your reply. I managed to open the googleapis.com Url. Now, a sample test case that browses microsoft.com is working but tests for my website are not working. I getting an error message: OpenQA.Selenium.WebDriverException : unknown error: net::ERR_CONNECTION_REFUSED (Session info: headless chrome=87.0.4280.66) – Mahesh Nov 20 '20 at 13:39
  • if you can please throw some light on my question. When the test will try to browse the website on the TFS build server, how it will get the website? Since it has not been hosted on the TFS server – Mahesh Nov 23 '20 at 06:22
  • Hi @Maxcom. If you directly visit the WebSite in the Browser on TFS Server machine, does it work fine? If it could work, you could try to use the IP address in the website url: `http://IP(X.X.X.X):8080/` You could share the code about connecting the Website. – Kevin Lu-MSFT Nov 24 '20 at 01:13
  • @Maxcom. Is there any update about this ticket? Feel free to let me know if the suggestions could give you some help. – Kevin Lu-MSFT Nov 25 '20 at 07:24
  • 1
    thank you for your comment. Actually, the firewall on the TFS Build server closed most of the URLs. And since the website/code is not hosted on the TFS Build server, I am not able to browse it with localhost/IP. Now, I am trying to instantiate IIS Express on the TFS Build server to run the website and then execute the test cases on it. Once again, thank you for your inputs. – Mahesh Nov 25 '20 at 08:02
  • @Maxcom Yes, that's the problem. The firewall indeed could affect the connection. Glad to know that you have found the method to solve it. If you have any progress, you can write an answer to share it. On the other hand, if the suggestions above could give you some help, you may consider accepting it. Thanks. – Kevin Lu-MSFT Nov 25 '20 at 08:50
  • 1
    Once I am done with the approach I am trying (IIS Express), I will post all the details here. Though your answer was really helpful. – Mahesh Nov 25 '20 at 09:04