我正在尝试使用selenium Nuint测试框架构建selenium-silverlight UI测试。 这是我的代码
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
using System.Text;
using OpenQA.Selenium.Interactions;
using System.Configuration;
using System.Threading;
using Selenium;
using ThoughtWorks.Selenium.Silvernium;
using DBServer.Selenium.Silvernium.Fixtures;
using NUnit.Framework;
namespace Rahul_Test
{
[TestFixture]
public class UnitTest1
{
protected static IWebDriver driver;
protected WebDriverWait wait;
protected StringBuilder verificationErrors;
private string baseURL;
protected static Actions builder;
protected Silvernium silvernium;
protected ISelenium selenium;
protected ICommandProcessor processor;
//initial setup
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com");
selenium.Start();
selenium.Open("http://atlas/Dev/Axioma/");
silvernium = new Silvernium(selenium, "InteractiveElement"); //this line throws error at runtime/while running tests in debug mode...
//Note: Build does not throw any errors on compilation
}
//open browser test case
[Test]
public void Login()
{
NUnit.Framework.Assert.IsFalse(false);
}
}
项目/解决方案构建时没有任何错误,但是当我从测试中调试/运行测试用例时,它失败并出现以下错误。
测试名称:登录
测试FullName:Rahul_Test.UnitTest1.Login
测试来源:c:\ Users \ rlodha \ Documents \ Visual Studio 2012 \ Projects \ SampleUITest \ SampleUITest \ UnitTest1.cs:第58行
测试结果:失败
测试时间:0:00:00.205
结果消息:SetUp:System.IO.FileNotFoundException:无法加载文件或程序集'Silvernium,Version = 1.0.4254.29979,Culture = neutral,PublicKeyToken = null'或其依赖项之一。
系统找不到指定的文件。 结果StackTrace:在Rahul_Test.UnitTest1.SetupTest()
我无法弄清楚为什么它能够在添加Silvernium Assembly参考时进行编译,但无法在运行/调试时加载Silvernium组件。
MSTest代码
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using System.Text;
using OpenQA.Selenium.Interactions;
using System.Configuration;
using System.Threading;
using Selenium;
using ThoughtWorks.Selenium.Silvernium;
//using NUnit.Framework;
namespace Rahul_Test
{
[TestClass]
public class UnitTest1
{
//copy this part for defining a class for IE and chrome
protected static IWebDriver driver;
protected WebDriverWait wait;
protected StringBuilder verificationErrors;
private string baseURL;
protected static Actions builder;
protected Silvernium silvernium;
protected ISelenium selenium;
//protected ICommandProcessor processor;
//initial setup
[TestInitialize]
public void SetupTest()
{
if (driver == null)
{
driver = new FirefoxDriver();
driver.Manage().Window.Maximize();
baseURL = "";
verificationErrors = new StringBuilder();
driver.Navigate().GoToUrl("http://atlas/Dev/Axioma/");
builder = new Actions(driver);
//processor=new
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com");
//selenium.Start();
//selenium.Open("http://atlas/Dev/Axioma/");
silvernium = new Silvernium(selenium, "InteractiveElement");
//var silverlightapp = new SilverlightApplicationFixture("localhost", 4444, "*firefox", "http://www.google.com");
// }
//wait = new WebDriverWait(driver, TimeSpan.FromSeconds(35));
//wait = new WebDriverWait(driver, TimeSpan.FromSeconds(Convert.ToInt16(ConfigurationManager.AppSettings["TimeOut"])));
}
}
//open browser test case
[TestMethod]
public void Login()
{
Assert.IsFalse(false);
}
}
}
MSTest的错误日志
Test Name:Login
Test FullName:Rahul_Test.UnitTest1.Login
Test Source:c:\Users\rlodha\Documents\Visual Studio 2012\Projects\SampleUITest\SampleUITest\UnitTest1.cs : line 57
Test Outcome:Failed
Test Duration:3.36805555555556E-06
Result Message:
Initialization method Rahul_Test.UnitTest1.SetupTest threw exception. System.IO.FileNotFoundException: System.IO.FileNotFoundException: Could not load file or assembly
'Silvernium, Version=1.0.4254.29979, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
The system cannot find the file specified.Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.exe.config
=== Pre-bind state information ===
LOG: DisplayName = Silvernium, Version=1.0.4254.29979, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Users/rlodha/Documents/Visual Studio 2012/Projects/SampleUITest/SampleUITest/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : SampleUITest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
.
Result StackTrace:at Rahul_Test.UnitTest1.SetupTest()
答案 0 :(得分:2)
我今天遇到了同样的错误。尝试将Silvernium dll的名称从Silvernium-version.number.dll更改为Silvernium.dll。
例如,我将我从Silvernium-1.1.dll更改为Silvernium.dll并且有效。
答案 1 :(得分:0)
重新安装selenium nuget包将解决问题。
前几分钟修复了同样的问题。