-
-
Save muditlambda/e0e693d9e88f7d7fba3fa27eeecf59ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NUnit.Framework; | |
using OpenQA.Selenium; | |
using OpenQA.Selenium.Chrome; | |
using OpenQA.Selenium.Firefox; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using OpenQA.Selenium.IE; | |
using System.Configuration; | |
/* For using Remote Selenium WebDriver */ | |
using OpenQA.Selenium.Remote; | |
namespace NUnit_Demo_1 | |
{ | |
class NUnitDemo_1 | |
{ | |
IWebDriver driver; | |
[SetUp] | |
public void startBrowser() | |
{ | |
String username = "user-name"; | |
String accesskey = "access-key"; | |
String gridURL = "@hub.lambdatest.com/wd/hub"; | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.SetCapability("user", "user-name"); | |
capabilities.SetCapability("accessKey", "access-key"); | |
capabilities.SetCapability("build", "Assert Test using LambdaTest (C#)"); | |
capabilities.SetCapability("name", "Assert Test using LambdaTest (C#)"); | |
capabilities.SetCapability("platform", "Windows 10"); | |
capabilities.SetCapability("browserName", "Internet Explorer"); | |
capabilities.SetCapability("version", "11.0"); | |
capabilities.SetCapability("ie.compatibility", 11001); | |
driver = new RemoteWebDriver(new Uri("https://" + username + ":" + accesskey + gridURL), capabilities, TimeSpan.FromSeconds(600)); | |
driver.Manage().Window.Maximize(); | |
} | |
[Test, Order(1)] | |
public void test_nunit_assertion_1() | |
{ | |
driver.Url = "https://www.lambdatest.com"; | |
System.Threading.Thread.Sleep(4000); | |
IWebElement login_button = driver.FindElement(By.XPath("//*[@id='navbarSupportedContent']/ul/li[6]/a")); | |
login_button.Click(); | |
/* Perform wait to check the output */ | |
System.Threading.Thread.Sleep(2000); | |
String expected_title = "login - Lambdatest"; | |
String actual_title = driver.Title; | |
Assert.That(expected_title, Is.EqualTo(actual_title).IgnoreCase); | |
Console.WriteLine("Test 1 Passed"); | |
} | |
[Test, Order(2)] | |
public void test_nunit_assertion_2() | |
{ | |
driver.Url = "https://accounts.lambdatest.com/login"; | |
String user_name_xpath = "//*[@id='app']/section/form/div/div/input[1]"; | |
String password_xpath = "//*[@id='app']/section/form/div/div/input[2]"; | |
String submit_button_xpath = "//*[@id='app']/section/form/div/div/button"; | |
System.Threading.Thread.Sleep(4000); | |
IWebElement user_name_element = driver.FindElement(By.XPath(user_name_xpath)); | |
user_name_element.SendKeys("validuser@gmail.com"); | |
// Raise assert if user-name is Empty | |
String user_name = user_name_element.GetAttribute("value"); | |
Console.WriteLine("User Name" + user_name); | |
Assert.That(user_name, Is.Not.Empty); | |
IWebElement password_field = driver.FindElement(By.XPath(password_xpath)); | |
password_field.SendKeys("Valid_Password"); | |
// Raise assert if password is Empty | |
String password = password_field.GetAttribute("value"); | |
Assert.That(password, Is.Not.Empty); | |
//Click the Login button | |
IWebElement submit_element = driver.FindElement(By.XPath(submit_button_xpath)); | |
submit_element.Submit(); | |
System.Threading.Thread.Sleep(2000); | |
// Since the login is successful, we check if the Welcome page is launched | |
String expected_title = "Welcome - LambdaTest"; | |
String actual_title = driver.Title; | |
Assert.That(expected_title, Is.EqualTo(actual_title).IgnoreCase); | |
Console.WriteLine("Test 2 Passed"); | |
} | |
[TearDown] | |
public void closeBrowser() | |
{ | |
driver.Quit(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment