簡體   English   中英

帶有Selenium的C#.NET-MVC應用程序在服務器上部署時不起作用

[英]C# .NET - MVC app with Selenium doesn't work when deployed on Server

我使用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永遠不會打開。

首先,您需要從

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM