#2 integration + ui tests

Preview:

Citation preview

eleks.com eleks.com

Integration testingAnd UI testing (Selenium Web driver)

Tests can be different

Integration tests featuresTest several components togetherUse dependencies (DB, Services, API, FS, AD, ...)Can have different behaviorRequire configurationResults can be different (depend on environment,

order of execution, multithreading, phase of Moon).

Integration tests featuresFollowing code can often be seen in

integration testsFile.Open(...)Connection.Close(...)Environment.MachineNameDateTime.NowTearDown(...)

Integration tests “Pro’s”

Pro’s:Make sure nuts and bolts fit togetherMake sure software stack components interact

smoothly Test behavior and infrastructure (tested code)/test

% is highReflect typical workflows

Integration tests “Con’s”

Con’s: Large time investmentHard to test all critical pathsHarder to localize source of errorsHarder to write and maintain

Project structure

Unit and integration tests should be separatedCommon practice is to end up project name with “.Tests” suffix

eleks.com eleks.com

Show me the code![integration test examples]

eleks.com eleks.com

UI testingTesting Web apps using Selenium

Wait, UI?Web Apps are Heterogeneous systems at mostDifferent technology stacks for backendComplex multi-layer and multi-tier systemsShould test all involved partsCan’t directly test server code and SQLEverything can go wrong...

Front end test featuresPros:Hide the complexity of a backendTests can reproduce exactly what users doCan detect errors not visible by other types of testsUI tests can be utilized for any automation in

general

Front end test featuresCons:Execution timeThird party tools/environmentsHard to maintainComplexityDynamic pages

What is it?

Selenium is a Functional Automation tool for Web apps Works with different languages, browsers, Oses etc. Interacts with Web app via UI

What is my options?Selenium 2 (Selenium Web Driver)Selenium 1 (Selenium RC)Selenium IDESelenium-Grid

More details at: http://docs.seleniumhq.org/docs/01_introducing_selenium.jsp

Selenium Web DriverInteractions via DRIVERsVarious drivers are supported:Chrome driver, Opera driver, Android driver, IOS

driver

UI Test key partsStart driverIWebDriver driver = new FirefoxDriver();Navigate to desired pagedriver.Navigate().GoToUrl(“...”);Find controls for interactionvar elem =

driver.FindElement(By.Name(“...”));Actelem.SendKeys(“Ok, Google”);

UI Test key partsWait/* WebDriverWait is preferred, but

Thread.Sleep will also work*/Assertsomething.Should.Be(...);Exit/Clean updriver.Close();

Selenium APIEasy to find controls/tagsBy name, id, css, xpath etc. Easy to navigateSelect active windowSwitch to urlEasy integrates with NUnitNo need for installers, manual process running etc

eleks.com eleks.com

UI automated tests example[Asp.Net 5 + NUnit + Selenium WebDriver]

It’s time to practice

Recommended