I am working on Selenium-based browser automation project, where some non-programming users define test cases in Selenium IDE, which we then add some custom logic to and run through our custom application. Our Application is written in C#, but basically works in a similar way as does the Selenium HTML Runner java application.
Now we hit the point where we needed loops in our test cases, so we installed the SelBlocks plugins in Selenium IDE. To make that also work in our custom application, I hope we could use the SelBlocks user extension JS file (from here https://raw.githubusercontent.com/refactoror/SelBlocks/master/user-extensions.js).
However, I couldn't get this working with WebDriverBackedSelenium and the ChromeDriver we are using. If I use ExecuteScript() on my WebDriverBackedSelenium object, I receive an UnsupportedOperationException. (The Start() method on the object has been called before!) According to the API description this sounded like the most suitable approach for globally registering the SelBlocks JavaScript code:
_selenium.AddScript(selBlocksScript, "selBlocks"); // throws UnsupportedOperationException
The strack trace:
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()
I then tried to use ExecuteScript on my ChromeDriver object (which is a less suitable approach, because it would execute the script in the context of the currently loaded web page, so I assume I would have to call it again and again, everytime before I use a SelBlocks extension method).
The call looks like this:
((IJavaScriptExecutor)driver).ExecuteScript(selBlocksScript, null);
The Chrome browser returns the message that the LOG object is unknown. Here's the stack trace:
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()
How should I proceed to add the SelBlocks script (or user extensions in general) to a customized Selenium WebDriver project? Or does the discussion on user extensions in Selenium 2 (aka WebDriver), as can be found here or here, mean that I need to implement all SelBlocks functions by myself to make them availale in WebDriver?