"Fossies" - the Fresh Open Source Software Archive 
Member "selenium-selenium-4.8.1/dotnet/test/webdriverbackedselenium/CompoundMutator.cs" (17 Feb 2023, 2961 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "CompoundMutator.cs" see the
Fossies "Dox" file reference documentation.
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 namespace Selenium.Internal.SeleniumEmulation
6 {
7 /// <summary>
8 /// A class that collects together a group of other mutators and applies
9 /// them in the order they've been added to any script that needs modification.
10 /// Any JS to be executed will be wrapped in an "eval" block so that a
11 /// meaningful return value can be created.
12 /// </summary>
13 internal class CompoundMutator : IScriptMutator
14 {
15 private List<IScriptMutator> mutators = new List<IScriptMutator>();
16
17 public CompoundMutator(string baseUrl)
18 {
19 this.AddMutator(new VariableDeclaration("selenium", "var selenium = {};"));
20 this.AddMutator(new VariableDeclaration("selenium.browserbot", "selenium.browserbot = {};"));
21 this.AddMutator(new VariableDeclaration("selenium.browserbot.baseUrl", "selenium.browserbot.baseUrl = '" + baseUrl + "';"));
22
23 this.AddMutator(new FunctionDeclaration("selenium.page", "if (!selenium.browserbot) { selenium.browserbot = {} }; return selenium.browserbot;"));
24 this.AddMutator(new FunctionDeclaration("selenium.browserbot.getCurrentWindow", "return window;"));
25 this.AddMutator(new FunctionDeclaration("selenium.page().getCurrentWindow", "return window;"));
26 this.AddMutator(new FunctionDeclaration("selenium.browserbot.getDocument", "return document;"));
27 this.AddMutator(new FunctionDeclaration("selenium.page().getDocument", "return document;"));
28
29 this.AddMutator(new SeleniumMutator("selenium.isElementPresent", JavaScriptLibrary.GetSeleniumScript("isElementPresent.js")));
30 this.AddMutator(new SeleniumMutator("selenium.isTextPresent", JavaScriptLibrary.GetSeleniumScript("isTextPresent.js")));
31 this.AddMutator(new SeleniumMutator("selenium.isVisible", JavaScriptLibrary.GetSeleniumScript("isVisible.js")));
32 this.AddMutator(new SeleniumMutator("selenium.browserbot.findElement", JavaScriptLibrary.GetSeleniumScript("findElement.js")));
33 }
34
35 #region IScriptMutator Members
36
37 public void Mutate(string script, StringBuilder outputTo)
38 {
39 StringBuilder nested = new StringBuilder();
40 foreach (IScriptMutator mutator in mutators)
41 {
42 mutator.Mutate(script, nested);
43 }
44
45 nested.Append("").Append(script);
46
47 outputTo.Append("return eval('");
48 outputTo.Append(escape(nested.ToString()));
49 outputTo.Append("');");
50 }
51
52 #endregion
53
54 internal void AddMutator(IScriptMutator mutator)
55 {
56 this.mutators.Add(mutator);
57 }
58
59 private string escape(String escapee)
60 {
61 return escapee
62 .Replace("\\", "\\\\")
63 .Replace("\n", "\\n")
64 .Replace("'", "\\'");
65 }
66 }
67 }