-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.cs
More file actions
71 lines (56 loc) · 3 KB
/
helper.cs
File metadata and controls
71 lines (56 loc) · 3 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
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace ael2;
public class helper
{
static string fname = "Akshat";
static string lname = "Gadhwal";
static string dob = "1999-12-12";
static string gender = "Male";
public static IWebDriver f1(IWebDriver driver){ // to get the driver of the iframe inside shadow dom
driver.Url = "https://app.cloudqa.io/home/AutomationPracticeForm";
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
IWebElement iframe = (IWebElement) jse.ExecuteScript("return document.querySelector('nestedshadow-iframe').shadowRoot.querySelector('iframe')");
driver.SwitchTo().Frame(iframe);
return driver;
}
public static string form1_(IWebDriver driver){ // for filling a simple form
string test_result = "failed";
driver.FindElement(By.Id("automationtestform")).FindElement(By.Id("fname")).SendKeys(fname);
driver.FindElement(By.Id("automationtestform")).FindElement(By.Id("lname")).SendKeys(lname);
driver.FindElement(By.Id("automationtestform")).FindElement(By.Id("dob")).SendKeys(dob);
driver.FindElement(By.Id("automationtestform")).FindElement(By.Id("Agree")).Click();
driver.FindElement(By.Id("automationtestform")).FindElement(By.XPath("//button[@type='submit']")).Click();
// validating the responses sent to the server
string str = driver.FindElement(By.TagName("pre")).Text;
var res = JObject.Parse(str);
var res_fname = res.ContainsKey("First Name") ? res["First Name"].ToString(): "_no_key";
var res_lname = res.ContainsKey("Last Name") ? res["Last Name"].ToString() : "_no_key";
var res_dob = res.ContainsKey("Date of Birth") ? res["Date of Birth"].ToString() : "_no_key";
var res_agree = res.ContainsKey("Agree") ? res["Agree"].ToString() : "_no_key";
if(fname == res_fname && lname == res_lname && res_dob == dob && res_agree == "Agree"){
test_result = "passed";
}
if(test_result != "passed"){
TestContext.Out.WriteLine(str);
}
return test_result;
}
public static string validator2(IWebDriver driver){ // response validator for the form of shadowDom of iframe-inside-shadowDom & for the form of nested shodowDom of iframe-inside-shadowDom
string test_result = "failed";
string str = driver.FindElement(By.TagName("pre")).Text;
var res = JObject.Parse(str);
var res_fname = res.ContainsKey("fname") ? res["fname"].ToString() : "_no_key";
var res_lname = res.ContainsKey("lname") ? res["lname"].ToString() : "_no_key";
var res_gender = res.ContainsKey("gender") ? res["gender"].ToString() : "no_key";
if(res_fname ==fname && res_lname == lname && res_gender == gender){
test_result = "passed";
}
if(test_result != "passed"){
TestContext.Out.WriteLine(str);
}
return test_result;
}
}