Post on 15-Apr-2017
WHYs and HOWs of Automation
Understanding need of test automation and
usage
By Shiva and Nalini
Expectations What are you hoping to get from this session?
Key Take Aways:
❏ Why is Test automation needed.
❏ Different ways and levels of automation.
❏ Hands on Automation exercise using Selenium.
Why Automation needed?
Repetitive Tests.
Larger No of Boundary
Value Tests
Frequent Code changes
Continuous Delivery
Wide Coverage.
Execution time, Money and Accuracy
Automation Myths
❖ Test Automation Costs Too Much
❖ We Have to Replace Manual Testers
❖ All Tests Will Be Automated
❖ Faster Software Release Cycle
❖ Quick ROI
What can be automated
Different Levels of Automation Implementation
API Layer
Presentation Layer
Business Layer
Presentation Layer
Presentation Layer
HOW?
...things get clearer when you can see them :)
Tech and Tools
Let’s get started with Selenium...lets see some examples...
Why Selenium?
● 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
Demo - try it yourself!
Automate a scenario using Selenium IDE
Scenario: Search an Element❏Open an URL ❏Search for an element❏Repeat the test in Selenium IDE
Initiate a Browser through Selenium
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);
Start Interacting with an application
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"));
By Name and XPath// Find By Name
WebElement pswd = driver.findElement(By.name("spree_user[password]"));
user_name.sendKeys("xt@xt.com");
pswd.sendKeys("xtxtxt");
// Find By Xpath
WebElement submit_button = driver.findElement(By.xpath("//*[@id='new_spree_user']/p[2]/input"));
submit_button.submit();
Scenario: Search for an element and add it to cart
@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()); }
Add Assertion to your Scenario
Closing notes...time flies when you’re automating tests...
Suggestions
● Automate as you go● Identify automatable
candidates● Identify levels to Implement
Automation● Cross role pairing
Key Take Aways:
❏ Why is Test automation needed.
❏ Different ways and levels of automation.
❏ Hands on Automation exercise using Selenium.
Questions
?