【发布时间】:2017-04-20 16:12:04
【问题描述】:
我正在从事基于 Selenium 的浏览器自动化项目,其中一些非编程用户在 Selenium IDE 中定义测试用例,然后我们将一些自定义逻辑添加到我们的自定义应用程序中并在其中运行。我们的应用程序是用 C# 编写的,但基本上与 Selenium HTML Runner java 应用程序的工作方式相似。
现在我们在测试用例中需要循环,因此我们在 Selenium IDE 中安装了 SelBlocks 插件。为了让它在我们的自定义应用程序中也能工作,我希望我们可以使用 SelBlocks 用户扩展 JS 文件(来自这里 https://raw.githubusercontent.com/refactoror/SelBlocks/master/user-extensions.js)。
但是,我无法使用 WebDriverBackedSelenium 和我们正在使用的 ChromeDriver 进行此操作。 如果我在 WebDriverBackedSelenium 对象上使用 ExecuteScript(),我会收到 UnsupportedOperationException。 (对象上的 Start() 方法之前已经调用过!)根据 API 描述,这听起来是最适合全局注册 SelBlocks JavaScript 代码的方法:
_selenium.AddScript(selBlocksScript, "selBlocks"); // throws UnsupportedOperationException
轨迹:
bei Selenium.WebDriverCommandProcessor.Execute(String commandName, String[] args)
bei Selenium.WebDriverCommandProcessor.DoCommand(String command, String[] args)
bei RHoDOS.CoreTestCase.Run(TestState state, Results results, IWebDriver driver) in D:\NB00382\Documents\Visual Studio 2015\Projects\RHoDOS-Dev1\RHoDOS\CoreTestCase.cs:Zeile 86.
bei RHoDOS.HtmlLauncher.LaunchHtmlTest(String testTitle, String filepath, WebDriverBackedSelenium selenium, IWebDriver driver, Results results) in D:\NB00382\Documents\Visual Studio 2015\Projects\RHoDOS-Dev1\RHoDOS\HtmlLauncher.cs:Zeile 71.
bei RHoDOS.HtmlLauncher.RunHtmlSuite(String filepath) in D:\NB00382\Documents\Visual Studio 2015\Projects\RHoDOS-Dev1\RHoDOS\HtmlLauncher.cs:Zeile 110.
bei RHoDOS.Program.Main(String[] args) in D:\NB00382\Documents\Visual Studio 2015\Projects\RHoDOS-Dev1\RHoDOS\Program.cs:Zeile 36.
bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()
然后我尝试在我的 ChromeDriver 对象上使用 ExecuteScript(这是一种不太合适的方法,因为它会在当前加载的网页的上下文中执行脚本,所以我假设我必须一次又一次地调用它,每次在我使用 SelBlocks 扩展方法之前)。
调用如下所示:
((IJavaScriptExecutor)driver).ExecuteScript(selBlocksScript, null);
Chrome 浏览器返回 LOG 对象未知的消息。这是堆栈跟踪:
bei OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) in C:\Users\U0558\Downloads\selenium-master\selenium-master\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:Zeile 1271.
bei OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) in C:\Users\U0558\Downloads\selenium-master\selenium-master\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:Zeile 1070.
bei OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScriptCommand(String script, String commandName, Object[] args) in C:\Users\U0558\Downloads\selenium-master\selenium-master\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:Zeile 1154.
bei OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScript(String script, Object[] args) in C:\Users\U0558\Downloads\selenium-master\selenium-master\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:Zeile 520.
bei RHoDOS.CoreTestCase.Run(TestState state, Results results, IWebDriver driver) in D:\NB00382\Documents\Visual Studio 2015\Projects\RHoDOS-Dev1\RHoDOS\CoreTestCase.cs:Zeile 87.
bei RHoDOS.HtmlLauncher.LaunchHtmlTest(String testTitle, String filepath, WebDriverBackedSelenium selenium, IWebDriver driver, Results results) in D:\NB00382\Documents\Visual Studio 2015\Projects\RHoDOS-Dev1\RHoDOS\HtmlLauncher.cs:Zeile 71.
bei RHoDOS.HtmlLauncher.RunHtmlSuite(String filepath) in D:\NB00382\Documents\Visual Studio 2015\Projects\RHoDOS-Dev1\RHoDOS\HtmlLauncher.cs:Zeile 110.
bei RHoDOS.Program.Main(String[] args) in D:\NB00382\Documents\Visual Studio 2015\Projects\RHoDOS-Dev1\RHoDOS\Program.cs:Zeile 36.
bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()
我应该如何继续将 SelBlocks 脚本(或一般的用户扩展)添加到自定义的 Selenium WebDriver 项目?还是在 here 或 here 中讨论的 Selenium 2(又名 WebDriver)中的用户扩展是否意味着我需要自己实现所有 SelBlocks 功能才能在 WebDriver 中使用它们?
【问题讨论】:
标签: c# selenium selenium-webdriver selenium-chromedriver selblocks-plugin