Automated testing using Selenium & NUnit

AlfredJettGrandeza 849 views 36 slides Nov 27, 2018
Slide 1
Slide 1 of 36
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36

About This Presentation

My slides for Automated testing using Selenium & NUnit on Devcon Davao Summit 2018


Slide Content

Automated Testing Alfred Jett Grandeza .NET & JS Developer, Trainer ajgrandeza.com Using Selenium & NUnit in C#

Outline Automated Testing Selenium NUnit Selenium Library Overview / Basics Setup Writing & Running Tests

What is automated testing? Test automation is a special way of executing tests where it compares the actual outcomes with predicted or expected outcomes using a special software Top Automated testing tools Selenium TestingWhiz TestComplete Ranorex Telerik TestStudio WatiN

Why automate tests? Increase effectiveness and productivity Increase efficiency Removes human error in the process Saves time and money Increase test coverage

What is Selenium? Selenium is a free automation testing framework for web applications Compatible with different browsers Selenium can interact with elements in a web page Click Type Extract data Basically almost anything you can do with a webpage Supports multiple languages like C#, Java, PHP, Python, etc

What is NUnit ? Nunit is a unit-testing framework for all .NET languages

NUnit > MSTest NUnit has a [ TestCase ] attribute that allows multiple parameters or testcases for a single unit test Faster than MsTest More mature than MsTest NUnit can inherit abstract classes to be TestFixtures , MSTest can’t NUnit is meant for Unit Testing. MSTests is more broad (i.e. Performance testing)

Selenium Webdriver Commands, LoCATORS , ETC

WebDriver SELENIUM

IWebDriver It’s an interface through which the user controls the browser ex. ChromeDriver implements IWebDriver

IWebDriver

Browser Navigation SELENIUM

Four Navigation Commands GoToUrl driver.Navigate (). GoToUrl (” google.com "); Back driver.Navigate ().Back(); Forward driver.Navigate ().Forward(); Refresh driver.Navigate ().Refresh();

WebElement Commands SELENIUM

What is WebElement ? WebElement represents the HTML document of a page

WebElement Properties

WebElement Methods

Locators SELENIUM

Locating Elements in a page Locating Elements in a page is done by using the FindElement or FindElements . You’ll need the By.Locator to use FindElement or FindElements Locators By.Id IWebElement element = driver.FindElement ( By.Id (” password ")); By.Name IWebElement element = driver.FindElement ( By.Name (”password ")); By.ClassName IWebElement element = driver.FindElement ( By.Name (”form-control ")); By.TagName IWebElement element = driver.FindElement ( By.TagName (”button")); By.Xpath IWebElement element = driver.FindElement ( By.Name (@” //*[@ id = " " password ""] "));

Getting element info Use Developer Tools to get element info like Element Id, Name, Class or even XPath

Getting element info Use Developer Tools to get the Xpath of an element

Installing NUnit and Selenium

Open Visual Studio 2015 or 2017 will do …

Add a new project to your existing solution or to your new solution

Create Unit Test Project

Open NuGet Manager

Install NUnit Make sure to select your Test Project

Make sure to select your Test Project Install Selenium.WebDriver

Make sure to select your Test Project Install Selenium.Chrome.WebDriver (or any preferred web browser)

DEMO selenium

Writing & Running Tests Selenium & nunit

Add a class (or a unit test class) on your test project

Add [ TestFixture ] Make it public Create a driver global variable Setup a “Setup” Setup a “ TearDown ”

DEMO Writing & Running Tests

Thanks for listening!

Sources http://toolsqa.com/selenium-c-sharp / https:// www.guru99.com/selenium-csharp-tutorial.html https:// seleniumhq.github.io/selenium/docs/api/dotnet https :// dzone.com/articles/top-10-automated-software-testing-tools