forked from florentbr/SeleniumBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTS_ExecuteScript.cs
More file actions
73 lines (61 loc) · 2.31 KB
/
TS_ExecuteScript.cs
File metadata and controls
73 lines (61 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Selenium.Tests.Internals;
using A = NUnit.Framework.Assert;
using CollectionAssert = NUnit.Framework.CollectionAssert;
using SetUp = NUnit.Framework.SetUpAttribute;
using TestCase = NUnit.Framework.TestCaseAttribute;
using TestFixture = NUnit.Framework.TestFixtureAttribute;
namespace Selenium.Tests {
[TestFixture(Browser.Firefox)]
[TestFixture(Browser.Opera)]
[TestFixture(Browser.Chrome)]
[TestFixture(Browser.IE)]
[TestFixture(Browser.PhantomJS)]
class TS_ExecuteScript : BaseBrowsers {
public TS_ExecuteScript(Browser browser)
: base(browser) { }
[SetUp]
public void SetUp() {
driver.Get("/elements.html");
}
[TestCase]
public void ShouldProcessWebElement() {
//Webelement
var ele = driver.FindElementById("input__text");
var resEle = (WebElement)driver.ExecuteScript("return arguments[0];", ele);
A.True(ele.Equals(resEle));
}
[TestCase]
public void ShouldProcessWebElements() {
//Webelements
var eles = driver.FindElementsByTag("input");
var resEles = (WebElements)driver.ExecuteScript("return arguments;", eles);
A.AreEqual(eles.Count, resEles.Count);
A.True(eles.First().Equals(resEles.First()));
}
[TestCase]
public void ShouldProcessPrimitive() {
//prinmitive int
var res = driver.ExecuteScript("return arguments[0] + 3;", 8);
A.AreEqual(11, res);
//prinmitive double
var valDouble = driver.ExecuteScript("return 1e-8;");
A.AreEqual(1e-8, valDouble);
}
[TestCase]
public void ShouldProcessDictionary() {
//Dictionary
var dict = new Selenium.Dictionary();
dict.Add("a", 987);
var resDict = (Dictionary)driver.ExecuteScript("return arguments[0];", dict);
CollectionAssert.AreEquivalent(dict, resDict);
}
[TestCase]
public void ShouldProcessList() {
//List
var list = new Selenium.List();
list.Add(987);
var resList = (Selenium.List)driver.ExecuteScript("return arguments;", list);
CollectionAssert.AreEquivalent(list, resList);
}
}
}