Named JavaScripts
Sometimes it is neccesary to execute JavaScript in the web browser. This might be to work around a limitation in a WebDriver implementation, such as web browsers which cannot enter values into date fields. At other times, JavaScript might be used to perform large-scale operations which would perform very poorly if conducted through many WebDriver interactions. This is particularly relevant where a Remote WebDriver is being used, in which each individual interaction suffers the latency and overhead of a remote network request/response.
Named scripts provide a mechanism by which developers may build a library of reusable pre-defined scripts and give them human-readable names. This way, when those scripts are used, they produce clear and concise entries in the Screenplay report. Additionally, named scripts provide .NET type safety via generic type parameters.
The classes
There are many script classes available, differing primarily in the number of paramaters which they accept. Here is a table listing them all. Pick the one which returns/does not return a result and which has the correct number of parameters for your script.
Using a script
Execute scripts within your performables using the builder method PerformableBuilder.ExecuteAScript or one of its many same-named overloads.
Generic type inference will offer the appropriate number and types of parameters and will expose a strongly-typed result if applicable.
Within the JavaScript body, the parameters are accessible via an arguments object.
Each parameter is assigned to this object using a zero-based index.
So, the first parameter value is arguments[0], the second arguments[1] and so on.