簡體   English   中英

在Visual Studio中使用C#和ChromeDriver進行MS Test的Selenium WebDriver

[英]Selenium WebDriver with MS Test using C# and ChromeDriver in Visual Studio

我正在嘗試使用chrome運行一些演示測試,但是出現以下錯誤:

An exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll but was not handled in user code

Additional information: The HTTP request to the remote WebDriver server for URL http://localhost:57523/session timed out after 60 seconds.

我已經在解決方案中添加了chromedriver,首先在聲明驅動程序時對路徑進行了硬編碼,但隨后發現了以下信息: Selenium WebDriver.ChromeDriver Nuget軟件包已安裝,但不適用於MSTest,並遵循了一些步驟(從2到4) )。

這是我正在使用的代碼:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace TestDemo1
{
    [TestClass]
    public class UnitTest1
    {
        static IWebDriver driver;

        [AssemblyInitialize]
        public static void SetUp(TestContext context)
        {
            //driver = new FirefoxDriver();
            driver = new ChromeDriver();
        }
        [TestMethod]
        public void TestMethod1()
        {
            driver.Navigate().GoToUrl("http://www.hazmeelchingadofavor.com");
        }

        [TestMethod]
        public void TestMethod2()
        {            
            driver.Navigate().GoToUrl("http://www.google.com");
            driver.FindElement(By.Id("gbqfq")).SendKeys("Selenium");
            driver.FindElement(By.Id("gbqfq")).SendKeys(Keys.Enter);
        }

        [AssemblyCleanup]
        public static void TearDown()
        {
            driver.Quit();
        }
    }
}

我正在使用VS Express 2013 for Web,以防萬一,我在使用firefox驅動程序時,一切運行正常

編輯10/23/2014:

  1. Chrome版本:38.0.2125.104 m
  2. Chrome驅動程序:2.11
  3. Selenium .Net:2.43.1
  4. Windows:7企業版64位

這是一個已知的錯誤: https : //code.google.com/p/chromedriver/issues/detail?id=928嘗試更新到Chrome驅動程序:2.12,此版本修復了另一個問題:已解決的問題916:Selenium(javascript)在Chrome應用[Pri-2]中切換到Webview窗口時失敗-https: //code.google.com/p/chromedriver/issues/detail? id =916

也許可以解決您的問題。 對我來說,降級chrome並使用舊的驅動程序可以解決問題

找到解決方案后,我們將更多的注意力放在了錯誤消息上,並找到了有關套接字的消息(記不起來真的很好),因此我們致電IT部門並要求有人過來,我們討論了該問題,並且可能的解決方案,因此解決方案:

長話短說:

殺毒軟件阻止了chromedriver使其無法連接,因此IT專家添加了一條規則,允許在chromedriver上完全執行,就是這樣,研究了數小時之久,問題是殺毒軟件(如果有)與您的IT部門進行類似的問題檢查

暫無
暫無

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

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