forked from LambdaTest/CSharp-Selenium-Sample
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsingleTest.cs
More file actions
70 lines (64 loc) · 3.15 KB
/
Copy pathsingleTest.cs
File metadata and controls
70 lines (64 loc) · 3.15 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
using System;
using OpenQA.Selenium;
using static System.Environment;
using OpenQA.Selenium.Safari;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
namespace csharp_selenium_lambdatest
{
class SingleTest
{
public static void execute()
{
// Update your lambdatest credentials
String LT_USERNAME = GetEnvironmentVariable("LT_USERNAME");
String LT_ACCESS_KEY = GetEnvironmentVariable("LT_ACCESS_KEY");
IWebDriver driver;
ChromeOptions capabilities = new ChromeOptions();
capabilities.BrowserVersion = "latest";
Dictionary<string, object> ltOptions = new Dictionary<string, object>();
ltOptions.Add("username", LT_USERNAME);
ltOptions.Add("accessKey", LT_ACCESS_KEY);
ltOptions.Add("platformName", "Windows 10");
ltOptions.Add("project", "Demo LT");
ltOptions.Add("build", "C# Build");
ltOptions.Add("sessionName", "C# Single Test");
ltOptions.Add("w3c", true);
ltOptions.Add("plugin", "c#-c#");
capabilities.AddAdditionalOption("LT:Options", ltOptions);
driver = new RemoteWebDriver(new Uri("https://hub.lambdatest.com/wd/hub/"), capabilities);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
try
{
Console.WriteLine("Navigating to todos app.");
driver.Navigate().GoToUrl("https://lambdatest.github.io/sample-todo-app/");
driver.FindElement(By.Name("li4")).Click();
Console.WriteLine("Clicking Checkbox");
driver.FindElement(By.Name("li5")).Click();
// If both clicks worked, then te following List should have length 2
IList<IWebElement> elems = driver.FindElements(By.ClassName("done-true"));
// so we"ll assert that this is correct.
if (elems.Count != 2)
throw new Exception();
Console.WriteLine("Entering Text");
driver.FindElement(By.Id("sampletodotext")).SendKeys("Yey, Let's add it to list");
driver.FindElement(By.Id("addbutton")).Click();
// lets also assert that the new todo we added is in the list
string spanText = driver.FindElement(By.XPath("/html/body/div/div/div/ul/li[6]/span")).Text;
if (!"Yey, Let's add it to list".Equals(spanText))
throw new Exception();
((IJavaScriptExecutor)driver).ExecuteScript("lambda-status=passed");
}
catch
{
((IJavaScriptExecutor)driver).ExecuteScript("lambda-status=failed");
}
finally{
driver.Quit();
}
}
}
}