很抱歉我搜索了谷歌的另一个新手问题,但找不到我的答案。在使用Javascript几周之后,我设法说服工作人员为selenium做一个C#概念证明。今天早上我开始了这个(我对C#几乎一无所知)。 我安装了最新的驱动程序/ Web浏览器/ selenium。
当我执行下面的代码时,我会在日志中得到这个。 Chrome会立即打开并关闭。我显然做错了什么?
----- Discover test started ------
NUnit Adapter 3.8.0.0: Test discovery starting
NUnit Adapter 3.8.0.0: Test discovery complete
========== Discover test finished: 1 found (0:00:00.18) ==========
------ Run test started ------
NUnit Adapter 3.8.0.0: Test execution started
Running all tests in C:\Users\snejad\Documents\Visual Studio 2017\Projects\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll
NUnit3TestExecutor converted 1 of 1 NUnit test cases
SetUp failed for test fixture ProofOfConcept.HomePageTest
System.InvalidOperationException : session not created exception
from disconnected: Unable to receive message from renderer
(Session info: chrome=60.0.3112.78)
(Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 6.1.7601 SP1 x86_64) (InsecureCertificate)
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor()
at ProofOfConcept.HomePageTest..ctor() in C:\Users\snejad\Documents\Visual Studio 2017\Projects\ClassLibrary1\ClassLibrary1\HomePageTest.cs:line 15
NUnit Adapter 3.8.0.0: Test execution complete
========== Run test finished: 1 run (0:00:02.561) ==========
enter code here
*****************************************************************************
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProofOfConcept
{
public class HomePageTest
{
IWebDriver driver = new ChromeDriver();
[Test]
public void myFirstTest()
{
driver.Navigate().GoToUrl("https://www.google.co.uk");
Assert.AreEqual("Google", driver.Title);
driver.Close();
driver.Quit();
}
}
}
Firefox错误
------发现测试开始------ NUnit Adapter 3.8.0.0:测试发现开始 NUnit Adapter 3.8.0.0:测试发现完成 ==========发现测试结果:1找到(0:00:00.173)========== ------运行测试开始------ NUnit Adapter 3.8.0.0:测试执行已开始 在C:\ Users \ snejad \ Documents \ Visual Studio 2017 \ Projects \ ClassLibrary1 \ ClassLibrary1 \ bin \ Debug \ ClassLibrary1.dll中运行所有测试 NUnit3TestExecutor转换了1个NUnit测试用例中的1个 测试夹具ProofOfConcept.HomePageTest的SetUp失败 OpenQA.Selenium.WebDriverException:无法找到一组匹配的功能 在OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) 在OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute,Dictionary`2参数) 在OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities) 在OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor,ICapabilities desiredCapabilities) 在OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions选项) 在OpenQA.Selenium.Firefox.FirefoxDriver..ctor() 在C:\ Users \ snejad \ Documents \ Visual Studio 2017 \ Projects \ ClassLibrary1 \ ClassLibrary1 \ HomePageTest.cs中的ProofOfConcept.HomePageTest..ctor():第15行 NUnit Adapter 3.8.0.0:测试执行完成 ==========运行测试完成:1次运行(0:00:01.6884)==========