-
Notifications
You must be signed in to change notification settings - Fork 0
/
BingTranslate.cs
157 lines (119 loc) · 4.4 KB
/
BingTranslate.cs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
//using OpenQA.Selenium.Firefox;
// Requires reference to IWebDriver.Support.dll
using OpenQA.Selenium.Support.UI;
using System.IO;
//package Test.Gmail;
public class BingTranslate
{
public static IWebDriver chromeDriver()
{
IWebDriver driver = new ChromeDriver("C:\\Users\\samkitjain\\Downloads\\chromedriver_win32");
WebDriverWait myWait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
// And now use this to visit Gmail
return driver;
}
public static void ChkInput(IWebDriver driver, String input)
{
IWebElement inputBox = driver.FindElement(By.CssSelector("textarea.srcTextarea"));
String text = inputBox.GetAttribute("value");
if (string.IsNullOrEmpty(text))
{
Console.WriteLine("Input field is empty");
}
else
{
Console.WriteLine("Input field is not empty");
}
if (text.Equals(input))
{
Console.WriteLine("Input Fields match");
}
else
{
Console.WriteLine("Error! Different Input field");
}
}
public static void ChkOutput(IWebDriver driver, String result)
{
IWebElement outputBox = driver.FindElement(By.CssSelector("div#destText"));
String text = outputBox.Text;
if (text.Equals(result))
{
Console.WriteLine("Test Result is same");
}
else
{
Console.WriteLine("Error! Wrong Test Result");
}
}
public static void GoogleSearch(IWebDriver driver, YamlReader read)
{
driver.Navigate().GoToUrl(read.Url);
IWebElement element = driver.FindElement(By.CssSelector("input[name='q']"));
element.SendKeys(read.SearchKey);
if (driver.Title.Equals(read.PageTitles[0]["title1"]))
{
Console.WriteLine("Title 1 successful-" + driver.Title);
}
else
{
Console.WriteLine("Error! Title one is wrong");
}
element.Submit();
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists(By.LinkText(read.SearchKey)));
}
public static void BingTranslator(IWebDriver driver, YamlReader read)
{
if (driver.Title.Equals(read.PageTitles[1]["title2"]))
{
Console.WriteLine("Title 2 successful-" + driver.Title);
}
else
{
Console.WriteLine("Error! Title 2 is wrong");
}
driver.FindElement(By.LinkText("Bing Translator")).Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists(By.XPath("//*[contains(@class,'srcTextarea')]")));
}
public static void InputText(IWebDriver driver, YamlReader read)
{
if (driver.Title.Equals(read.PageTitles[2]["title3"]))
{
Console.WriteLine("Title 3 successful-" + driver.Title);
}
else
{
Console.WriteLine("Error! Title 3 is wrong");
}
String s = read.TestData;
driver.FindElement(By.XPath("//*[contains(@class,'srcTextarea')]")).SendKeys(s);
ChkInput(driver, s);
}
public static void SelectLanguage(IWebDriver driver, YamlReader read)
{
driver.FindElement(By.CssSelector("div.col.translationContainer.destinationText div.LS_Header")).Click();
driver.FindElement(By.CssSelector("div.col.translationContainer.destinationText td[value='"+read.Language+"'] ")).Click();
Thread.Sleep(1000);
ChkOutput(driver, read.TestResult);
}
public static YamlReader Read() {
var input = File.OpenText("C:/Users/samkitjain/Documents/Visual Studio 2017/Projects/ConsoleApp2/ConsoleApp2/Yaml.yml");
var deserializerBuilder = new DeserializerBuilder().WithNamingConvention(new CamelCaseNamingConvention());
var deserializer = deserializerBuilder.Build();
YamlReader result = deserializer.Deserialize<YamlReader>(input);
return result; }
public static void Main() {
YamlReader read = Read();
IWebDriver d = chromeDriver();
GoogleSearch(d, read);
BingTranslator(d, read);
InputText(d, read);
SelectLanguage(d, read);
}
}