Whys and Hows of Automation

30
WHYs and HOWs of Automation Understanding need of test automation and usage By Shiva and Nalini

Transcript of Whys and Hows of Automation

Page 1: Whys and Hows of Automation

WHYs and HOWs of Automation

Understanding need of test automation and

usage

By Shiva and Nalini

Page 2: Whys and Hows of Automation

Expectations What are you hoping to get from this session?

Page 3: Whys and Hows of Automation

Key Take Aways:

❏ Why is Test automation needed.

❏ Different ways and levels of automation.

❏ Hands on Automation exercise using Selenium.

Page 4: Whys and Hows of Automation

Why Automation needed?

Page 5: Whys and Hows of Automation

Repetitive Tests.

Larger No of Boundary

Value Tests

Frequent Code changes

Continuous Delivery

Wide Coverage.

Execution time, Money and Accuracy

Page 6: Whys and Hows of Automation

Automation Myths

Page 7: Whys and Hows of Automation

❖ Test Automation Costs Too Much

❖ We Have to Replace Manual Testers

❖ All Tests Will Be Automated

❖ Faster Software Release Cycle

❖ Quick ROI

Page 8: Whys and Hows of Automation

What can be automated

Page 9: Whys and Hows of Automation

Different Levels of Automation Implementation

API Layer

Presentation Layer

Business Layer

Presentation Layer

Presentation Layer

Page 10: Whys and Hows of Automation

HOW?

...things get clearer when you can see them :)

Page 11: Whys and Hows of Automation

Tech and Tools

Page 12: Whys and Hows of Automation
Page 13: Whys and Hows of Automation

Let’s get started with Selenium...lets see some examples...

Page 14: Whys and Hows of Automation

Why Selenium?

Page 15: Whys and Hows of Automation

● OS independent

● Multiple languages Python, PERL, RUBY, PHP, .NET(C#), Java

● Supports lot many browsers

● Open source and have a good community base

● Robust methods to locate elements

Page 16: Whys and Hows of Automation

Demo - try it yourself!

Page 17: Whys and Hows of Automation

Automate a scenario using Selenium IDE

Page 18: Whys and Hows of Automation

Scenario: Search an Element❏Open an URL ❏Search for an element❏Repeat the test in Selenium IDE

Page 19: Whys and Hows of Automation

Initiate a Browser through Selenium

Page 20: Whys and Hows of Automation

Open application through Firefox and ChromeChrome:

System.setProperty("webdriver.chrome.driver", "/<path to chrome driver>/chromedriver");

String url = "http://localhost:3000";

WebDriver driver = new ChromeDriver();

driver.get(url);

Firefox:

System.setProperty("webdriver.gecko.driver","/Users/shivalis/Downloads/geckodriver");

String url = "http://localhost:3000";

WebDriver driver = new FirefoxDriver();

driver.get(url);

Page 21: Whys and Hows of Automation

Start Interacting with an application

Page 22: Whys and Hows of Automation

Scenario: Login to Spree e-Commerce ApplicationFind By ID

System.setProperty("webdriver.chrome.driver", "/Users/shivalis/Downloads/chromedriver");

String url = "http://localhost:3000";

WebDriver driver = new ChromeDriver();

driver.get(url);

// Find By Id

WebElement login_icon = driver.findElement(By.id("link-to-login"));

login_icon.click();

WebElement user_name = driver.findElement(By.id("spree_user_email"));

Page 23: Whys and Hows of Automation

By Name and XPath// Find By Name

WebElement pswd = driver.findElement(By.name("spree_user[password]"));

user_name.sendKeys("[email protected]");

pswd.sendKeys("xtxtxt");

// Find By Xpath

WebElement submit_button = driver.findElement(By.xpath("//*[@id='new_spree_user']/p[2]/input"));

submit_button.submit();

Page 24: Whys and Hows of Automation

Scenario: Search for an element and add it to cart

Page 25: Whys and Hows of Automation

@Test public void searchForAnElement() {

System.setProperty("webdriver.chrome.driver", "/Users/shivalis/Downloads/chromedriver"); String url = "http://localhost:3000"; WebDriver driver = new ChromeDriver(); driver.get(url);// Find By Id WebElement search_box = driver.findElement(By.id("keywords")); search_box.sendKeys("Bag"); WebElement search_bar = driver.findElement(By.xpath("//*[@id=\"search-bar\"]/form/input[2]")); search_bar.click();

// Find multiple elements List<WebElement> products = driver.findElements(By.xpath("//*[@id=\"products\"]/li")); System.out.println(products.size()); Assert.assertEquals("Size doesn't match ",2, products.size()); }

Page 26: Whys and Hows of Automation

Add Assertion to your Scenario

Page 27: Whys and Hows of Automation

Closing notes...time flies when you’re automating tests...

Page 28: Whys and Hows of Automation

Suggestions

● Automate as you go● Identify automatable

candidates● Identify levels to Implement

Automation● Cross role pairing

Page 29: Whys and Hows of Automation

Key Take Aways:

❏ Why is Test automation needed.

❏ Different ways and levels of automation.

❏ Hands on Automation exercise using Selenium.

Page 30: Whys and Hows of Automation

Questions

?