View
73
Download
1
Embed Size (px)
Citation preview
Jonathan Morar & Ingo Philipp© 2017 by .
Test Automation For Manual TestersTransitioning to Continuous Testing.
© 2017 by
*Bottom Line. Continuous testing requires automation.
UI
API
Today Tomorrow
Exploratory Tests
Automated UI Tests
API Tests
Orchestrated Service Virtualization
80%Manual Testing
+85%
20%Automated
Testing - key enabler for high automation rates -
Testing Future
© 2017 by
Automation Approaches
Record & ReplayLinear Framework
SophisticatedFramework
Model-BasedAutomation
1st Generation 2nd Generation 3rd Generation
Script-Based
10%Automation
30%Automation
90%Automation
Tosca Recorder
© 2017 by
Fram
ewor
k M
atur
ity
Enterprise E2E Framework
Reinvent the wheel for each technology, and integrate them all.
Abstraction Layer(s)
…
FrameworkStability
FrameworkModularity
FrameworkFlexibility
FrameworkReadability
FrameworkMaintainability
Integrate Integrate Integrate Integrate
EnterpriseStatus
© 2017 by
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
namespace SeleniumVehicleInsuranceWDTests { enum Browser { IE, Chrome, Firefox }
class CommonBasics { public static string FindVehicleInsurancePath(Browser browser) { string vehicleInsurancePath = Environment.GetEnvironmentVariable("TRICENTIS_HOME"); vehicleInsurancePath = Path.Combine(vehicleInsurancePath, @“…\Main.html");
string finalPath = string.Empty; if (browser == Browser.IE) { finalPath = vehicleInsurancePath; } else { foreach (string split in vehicleInsurancePath.Split('\\')) { finalPath += Uri.EscapeUriString(split) + "\\"; } finalPath = finalPath.Substring(0, finalPath.Length - 1); if (browser == Browser.Firefox) { finalPath = @"file://" + finalPath; } }
return finalPath; }
public static void VerifyText(string expected, string actual, StringBuilder verificationErrors) { try { Assert.AreEqual(expected, actual); } catch (AssertionException e) { verificationErrors.Append(e.Message); } }
public static bool IsElementPresent(IWebDriver driver, By by) { try { driver.FindElement(by); return true; } catch (NoSuchElementException) { return false; } }
public static void WaitForSuccess(Func<bool> conditionToFulfill) { for (int second = 0; ; second++) { if (second >= 60) Assert.Fail("timeout"); try { bool invoked = conditionToFulfill.Invoke(); if (invoked) break; } catch (Exception) { } Thread.Sleep(500); } }
public static bool IsAlertPresent(IWebDriver driver) { try { driver.SwitchTo().Alert(); return true; } catch (NoAlertPresentException) { return false; } }
public static string CloseAlertAndGetItsText(IWebDriver driver, bool acceptNextAlert) { IAlert alert = driver.SwitchTo().Alert(); string alertText = alert.Text; if (acceptNextAlert) { alert.Accept(); } else { alert.Dismiss(); } return alertText; } }}
using System;using System.IO;using System.Text;using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;using OpenQA.Selenium.Firefox;using OpenQA.Selenium.IE;using OpenQA.Selenium.Support.UI;
namespace SeleniumVehicleInsuranceWDTests { [TestFixture] public class VehicleInsuranceAutomobile { private IWebDriver driver; private StringBuilder verificationErrors; private string baseURL; private bool acceptNextAlert = true;
private string gender;
private string insuranceSum;
private string paymentOption;
private string courtesyCar;
private string firstName;
private string lastName;
private string dateOfBirth;
private string make;
private string performance;
private string yearOfConstruction;
private string nrOfSeats;
private string listPrice;
private string mileageYear;
private string fuel;
private string sum;
private string sumpXpath;
[SetUp] public void SetupTest() { this.driver = new FirefoxDriver(); this.baseURL = CommonBasics.FindVehicleInsurancePath(Browser.Firefox); this.driver.Navigate().GoToUrl(this.baseURL);
this.driver.SwitchTo().Frame("NavigationMenu"); this.driver.FindElement(By.Id("VehicleInsurance")).Click(); this.driver.SwitchTo().DefaultContent();
this.verificationErrors = new StringBuilder(); }
[TearDown] public void TeardownTest() { try { this.driver.Quit(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual("", this.verificationErrors.ToString()); }
[Test] public void TheVehicleInsuranceAudiPassedTest() { this.gender = "male"; this.insuranceSum = “7.000.000,00"; this.paymentOption = “Yearly"; this.courtesyCar = "Courtesy Car"; this.firstName = “Max"; this.lastName = “Mustermann"; this.dateOfBirth = “12/10/1977"; this.make = “Audi"; this.performance = “200"; this.yearOfConstruction = "2016"; this.nrOfSeats = “5"; this.listPrice = “25000"; this.mileageYear = “15000"; this.fuel = "Petrol"; this.sum = “1.535,22"; this.sumpXpath = "tr[10]/td[2]";
this.InputAutomobileData(); this.VerifyAutomobileData(); }
private void InputAutomobileData() { CommonBasics.WaitForSuccess(()=> driver.FindElement(By.Id("SubmitButton")) != null);
this.driver.FindElement(By.Id("SubmitButton")).Click(); this.driver.FindElement(By.Id("Make")).Clear();
this.driver.FindElement(By.Id("Make")).SendKeys(make); this.driver.FindElement(By.Id("Performance")).Clear(); this.driver.FindElement(By.Id("Performance")).SendKeys(performance); new SelectElement(this.driver.FindElement(By.Id("Year"))).SelectByText(year);
new SelectElement(this.driver.FindElement(By.Id("Seats"))).SelectByText(Seats); new SelectElement(this.driver.FindElement(By.Id("Fuel"))).SelectByText(fuel); this.driver.FindElement(By.Id("ListPrice")).Clear(); this.driver.FindElement(By.Id("ListPrice")).SendKeys(listPrice); this.driver.FindElement(By.Id("mileageYear")).Clear(); this.driver.FindElement(By.Id("mileageYear")).SendKeys(mileageYear); this.driver.FindElement(By.Id("Next")).Click(); this.driver.FindElement(By.Id("FirstName")).Clear(); this.driver.FindElement(By.Id("FirstName")).SendKeys(this.firstName); this.driver.FindElement(By.Id("LastName")).Clear(); this.driver.FindElement(By.Id("LastName")).SendKeys(this.lastName); this.driver.FindElement(By.Id("DateOfBirth")).Clear(); this.driver.FindElement(By.Id("DateOfBirth")).SendKeys(this.dateOfBirth); new SelectElement(this.driver.FindElement(By.Id("Gender"))).SelectByText(this.gender); this.driver.FindElement(By.Id("YoungDriversRadioYoung")).Click(); this.driver.FindElement(By.Id("YoungDriversRadioOld")).Click(); this.driver.FindElement(By.Id("Next")).Click(); new SelectElement(this.driver.FindElement(By.Id("InsuranceSum"))).SelectByText(this.insuranceSum); new SelectElement(this.driver.FindElement(By.Id("PaymentOption"))).SelectByText(this.paymentOption); this.driver.FindElement(By.Id("ComprehensiveCover")).Click(); new SelectElement(this.driver.FindElement(By.Id("CourtesyCar"))).SelectByText(this.courtesyCar); this.driver.FindElement(By.Id("SubmitButton")).Click(); this.driver.FindElement(By.XPath("//input[@value='Send Quote']")).Click(); CommonBasics.WaitForSuccess(() => "100%" == this.driver.FindElement(By.Id("progress")).Text); }
private void VerifyAutomobileData() { CommonBasics.VerifyText(this.sum, driver.FindElement(By.XPath("//table[@id='PriceList']/tbody/" + this.sumpXpath)).Text, verificationErrors); } }}
It’s like saying goodbye totest automation.
this.paymentOption = “Yearly"; this.courtesyCar = "Courtesy Car"; this.firstName = “Max"; this.lastName = “Mustermann"; this.dateOfBirth = “12/10/1977"; this.make = “Audi"; this.performance = “200"; this.yearOfConstruction = "2016"; this.nrOfSeats = “5"; this.listPrice = “25000"; this.mileageYear = “15000"; this.fuel = "Petrol"; this.sum = “1.535,22"; this.sumpXpath = "tr[10]/td[2]";
this.InputAutomobileData(); this.VerifyAutomobileData(); }
private void InputAutomobileData() { CommonBasics.WaitForSuccess(()=> driver.FindElement(By.Id("SubmitButton")) != null);
this.driver.FindElement(By.Id("SubmitButton")).Click(); this.driver.FindElement(By.Id("Make")).Clear();
this.driver.FindElement(By.Id("Make")).SendKeys(make); this.driver.FindElement(By.Id("Performance")).Clear(); this.driver.FindElement(By.Id("Performance")).SendKeys(performance); new SelectElement(this.driver.FindElement(By.Id("Year"))).SelectByText(year);
new SelectElement(this.driver.FindElement(By.Id("Seats"))).SelectByText(Seats); new SelectElement(this.driver.FindElement(By.Id("Fuel"))).SelectByText(fuel); this.driver.FindElement(By.Id("ListPrice")).Clear(); this.driver.FindElement(By.Id("ListPrice")).SendKeys(listPrice); this.driver.FindElement(By.Id("mileageYear")).Clear(); this.driver.FindElement(By.Id("mileageYear")).SendKeys(mileageYear); this.driver.FindElement(By.Id("Next")).Click(); this.driver.FindElement(By.Id("FirstName")).Clear(); this.driver.FindElement(By.Id("FirstName")).SendKeys(this.firstName); this.driver.FindElement(By.Id("LastName")).Clear(); this.driver.FindElement(By.Id("LastName")).SendKeys(this.lastName); this.driver.FindElement(By.Id("DateOfBirth")).Clear(); this.driver.FindElement(By.Id("DateOfBirth")).SendKeys(this.dateOfBirth);
Do you see the business information?
Script-BasedBrowser