C#.NET - 使用Selenium的MVC应用程序在服务器

时间:2015-07-02 11:09:07

标签: c# asp.net asp.net-mvc selenium localhost

我使用C#+ .NET - MVC创建了一个登录自动化应用程序。

我的应用程序在我的本地计算机上运行完美,并保存数据库中的所有内容。

在我的本地计算机上部署应用程序后,索引视图会收到电子邮件和密码,将它们发送到数据库并保存。下一步是使用Selenium启动WebDriver(Firefox或Chrome在笔记本电脑上工作)。没有任何反应。它会一直在本地主机上等待,并且在一段时间后Chrome和FF都会超时。

    [HttpGet]
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult getInformation()
    {
        email = Request["getEmail"].ToString();
        password = Request["getPassword"].ToString();
        saveLogin();
        return RedirectToAction("gatherer");
    }

    public ActionResult gatherer()
    {
        facebookLogin();
        return null;
    }

    private static void facebookLogin()
    {
        chrome = new FirefoxDriver();
        chrome.Navigate().GoToUrl("http://facebook.com");
        chrome.FindElement(By.Id("email")).SendKeys(email);
        chrome.FindElement(By.Id("pass")).SendKeys(password);
        chrome.FindElement(By.Id("loginbutton")).Click();
    }

这很简单,它再次在我的本地计算机上运行。但是在服务器上的IIS上部署,却没有。换句话说:webdriver永远不会打开。

1 个答案:

答案 0 :(得分:1)

首先你需要改变

chrome = new FirefoxDriver();

DesiredCapabilities capability = DesiredCapabilities.Firefox();
Uri url = new Uri("http://REMOTE_IP:5050/wd/hub");
IWebDriver chrome = new RemoteWebDriver(url, capability);

然后下载Selenium Standalone服务器并使用命令提示符使用

启动它
java -jar C:\selenium-server-standalone-2.24.1.jar -interactive -port 5050
相关问题