[英]C# .NET - MVC app with Selenium doesn't work when deployed on Server
I made a login automation application with C# + .NET - MVC. 我使用C#+ .NET-MVC开发了一个登录自动化应用程序。
My application works perfectly on my local computer and saves everything on the database. 我的应用程序可以在本地计算机上完美运行,并将所有内容保存在数据库中。
Once I deployed my application on our local machine, the Index View receives the email and password, sends them to the database and saves them. 一旦将应用程序部署到本地计算机上,索引视图就会收到电子邮件和密码,然后将它们发送到数据库并保存。 The next step firing up a WebDriver (Firefox or Chrome worked on laptop) with Selenium.
下一步,使用Selenium启动WebDriver(在笔记本电脑上运行Firefox或Chrome)。 Here, nothing happens.
在这里,什么都没有发生。 It keeps waiting on the localhost forever and both Chrome and FF timeout after a certain period of time.
一段时间后,它将一直等待本地主机,并且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();
}
This is very simple and it worked on my local computer again. 这非常简单,并且可以在我的本地计算机上再次使用。 But deployed on IIS on the server, it doesn't.
但是没有部署在服务器上的IIS上。 In other words : the webdriver never opens.
换句话说:webdriver永远不会打开。
First you need to change from 首先,您需要从
chrome = new FirefoxDriver();
To 至
DesiredCapabilities capability = DesiredCapabilities.Firefox();
Uri url = new Uri("http://REMOTE_IP:5050/wd/hub");
IWebDriver chrome = new RemoteWebDriver(url, capability);
Then Download Selenium Standalone server and use command prompt to initiate it using 然后下载Selenium Standalone服务器并使用命令提示符使用以下命令启动它
java -jar C:\selenium-server-standalone-2.24.1.jar -interactive -port 5050
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.