-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleSteps.cs
More file actions
77 lines (68 loc) · 3.34 KB
/
SingleSteps.cs
File metadata and controls
77 lines (68 loc) · 3.34 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
74
75
76
77
using System;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using TechTalk.SpecFlow;
namespace BS_Specflow
{
[Binding]
public class SingleSteps
{
IWebDriver driver;
String username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");
String accessKey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");
public SingleSteps()
{
OpenQA.Selenium.Chrome.ChromeOptions capability = new OpenQA.Selenium.Chrome.ChromeOptions();
capability.AddAdditionalCapability("os_version", "10", true);
capability.AddAdditionalCapability("browser", "Chrome", true);
capability.AddAdditionalCapability("browser_version", "latest", true);
capability.AddAdditionalCapability("os", "Windows", true);
capability.AddAdditionalCapability("name", "Google Search Test", true); // test name
capability.AddAdditionalCapability("build", "browserstack-specflow-sample", true); // CI/CD job or build name
capability.AddAdditionalCapability("browserstack.user", username, true);
capability.AddAdditionalCapability("browserstack.key", accessKey, true);
driver = new RemoteWebDriver(
new Uri("https://hub-cloud.browserstack.com/wd/hub/"), capability);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
}
[Given(@"I am on the Bstackdemo website and click on signin")]
public void GivenIAmOnTheBstacdemoWebsiteAndClickOnSignin()
{
driver.Navigate().GoToUrl("https://bstackdemo.com/");
driver.FindElement(By.Id("signin")).Click();
}
[When(@"I enter ""(.*)"" and ""(.*)""")]
public void WhenIEnter(string username,String password)
{
try
{
driver.FindElement(By.CssSelector("#username input")).SendKeys(username);
driver.FindElement(By.CssSelector("#username input")).SendKeys(Keys.Enter);
driver.FindElement(By.CssSelector("#password input")).SendKeys(password);
driver.FindElement(By.CssSelector("#password input")).SendKeys(Keys.Enter);
driver.FindElement(By.Id("login-btn")).Click();
}
catch (Exception e)
{
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {\"action\": \"setSessionStatus\", \"arguments\": {\"status\":\"failed\", \"reason\": \"Something went wrong!\"}}");
Console.WriteLine(e);
}
}
[Then(@"I should see user as ""(.*)""")]
public void ThenIShouldSeeUserAs(string user)
{
String verifyUser = driver.FindElement(By.ClassName("username")).Text;
if (verifyUser.Equals(user))
{
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {\"action\": \"setSessionStatus\", \"arguments\": {\"status\":\"passed\", \"reason\": \"Expected\"}}");
}
else
{
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {\"action\": \"setSessionStatus\", \"arguments\": {\"status\":\"failed\", \"reason\": \"Unexpected\"}}");
}
System.Threading.Thread.Sleep(5000);
driver.Quit();
}
}
}