0

I am trying to create a simple automation task. For now I want to log in to the webpage. This all works fine when I run the test in Visual Studio 2017. However this will need to be executed as an exe on regular interval in windows system. When I run the executable it hangs after displaying:

Starting ChromeDriver 2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a)

on port 9515

Only local connections are allowed.

I understand this is just info not an error per most SO posts related to this issue such as - When running WebDriver with Chrome browser, getting message, "Only local connections are allowed" even though browser launches properly (note: my browser does not launch)

How do I run the test code as an executable? Do I have to write additional code to invoke the test when running as executable?

Nuget Version Info

namespace RevuSeleniumAutomation
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.PhantomJS;
using System;

[TestClass]
public class RevuAutomater
{
    private string baseURL = "http://example.com/";
    private RemoteWebDriver driver;
    private string browser;
    public TestContext TestContext { get; set; }

    [TestMethod]
    [TestCategory("Selenium")]
    [Priority(1)]
    [Owner("Chrome")]

    public void AutomateSite()
    {
        driver = new ChromeDriver();
        driver.Manage().Window.Maximize();
        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
        driver.Navigate().GoToUrl(this.baseURL);
        driver.FindElementById("UserName").SendKeys("user");
        driver.FindElementById("Password").SendKeys("12345");
    }

    [TestCleanup()]
    public void MyTestCleanup()
    {
        driver.Quit();
    }

    [TestInitialize()]
    public void MyTestInitialize()
    {
    }
}

}

The cmd window message after launching exe

Thank you for your time.

Wilson Vargas
  • 2,841
  • 1
  • 19
  • 28
arch tech
  • 3
  • 3
  • Did you run in Visual Studio and as EXE on same machine? If so, it should pass as run in Visual Studio because both use same chrome and chromedriver.exe. – yong Sep 20 '17 at 23:39
  • the issue is chrome driver hangs & you need to quit all chromedriver process before invoking the exe again. Example cmd command can be used as first part of your code: "taskkill /F /IM chromedriver.exe /T" which needs to be run on cmd – thebadguy Sep 21 '17 at 04:11

1 Answers1

1

To run as EXE I think there are two options:

1) not with selenium server or grid
. you need package the chromedriver.exe with your code into the EXE
. you code need to calculate the path of chromedriver.exe in runtime, because you don't know user will put the EXE in which folder
. specify chromedriver.exe by ChromeOptions to tell selenium where to find it when create driver instance

Shortage of this way: a chromedriver.exe of certian version support limited chrome verions, not all chrome verions, you need to tell user which chrome the EXE support.

2) use selenium server/grid
. you code need accept selenium server/grid address from a config file which user can modify it
. create RemoteWebDriver instance with above address, not ChromeDriver in code
. no need to package chromedriver.exe with your code

Shortage of this way: A selenium server/grid need be ready before execute EXE, But your code no need to consider the compatibility of chrome and chromedriver.exe, because they had been considered when setup selenium server/grid.

yong
  • 13,357
  • 1
  • 16
  • 27
  • For option 1, you can use config file as option 2 to setting the path of chromedriver.exe by user self. – yong Sep 21 '17 at 00:03