automated testing basics for test engineers

32
Automated testing foundations with Selenium and C# by Oleksandr Turevskiy

Upload: oleksandr-turevskiy

Post on 16-Jul-2015

80 views

Category:

Software


3 download

TRANSCRIPT

Page 1: Automated testing basics for test engineers

Automated testing foundationswith Selenium and C#

by Oleksandr Turevskiy

Page 2: Automated testing basics for test engineers

The goal

I want to:

• Remind the basic ideas of software testing, programming, automation and Web

• Give hand-on experience creating the automated tests for selenium

• Provide the tools and basis for the following self-education

Disclaimer

• All ideas in this course came purely from my experience and

• They may not correspond to Infopulse’s or generally accepted views

• They may not be true at all , but may be helpful sometimes

Page 3: Automated testing basics for test engineers

Target audience and entry criteria

• You are:

• Junior+ test engineers or developers with some experience in both development and testing

• You have:

• Basic software development skills: you know what is cycle, inheritance and recursion

• Experience using some popular IDE like Visual Studio or Eclipse

• PI English level: you can read, listen and even understand

• Software development process basics knowledge: what is testing, why to automate when bug is really fixed

• Understanding of Web concepts: HTTP, HTML, CSS, JavaScript

• Practical experience using and testing with different browsers and configuring them

• You want to be:

• Test engineers with automation knowledge

• Developers of the automated UI tests

Page 4: Automated testing basics for test engineers

What you need?

• Computer with Visual Studio 2012, Java SE and Selenium. Download a virtual machine with all the software set up from here: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX

• To use the virtual machine – VMware Player installed. Take one from here: XXXXXXXXXXXXXXXXXXXX

• Access to the Internet for documentation

• Your time and desire

Page 5: Automated testing basics for test engineers

Schedule

• Entry poll to understand the initial level

• Duration:

• Three times per week, 2 h per day

• 2 weeks

• 12h in total

• Home work is mandatory

• Final assessment

Page 6: Automated testing basics for test engineers

Why Selenium?

•What Selenium is:

• FREE framework for creating the automated Web UI tests

• Supports various browsers,

• Supports distributed test runs,

• Create tests in you favorite development environment (Java, C#, Python, etc.)

•What Selenium is not:

• Web UI testing only. No Windows apps. No services.

• No tests infrastructure support in core libraries. You can use your framework (Java, .NET etc.) however.

Page 7: Automated testing basics for test engineers

Why C#?

• Simply: I do know it.

• The differences are minor

• Java libraries for Selenium are somewhere more advanced and just a bit different

•We will try a small Java example at the end

Page 8: Automated testing basics for test engineers

Day 1 of 6: Agenda

• Entry Poll

• Testing and quality

• Why to test?

• Why not to test?

• Continuous integration and unit tests integration

• Automation: When? Why? How Much?

• Why to automate?

• Why to don’t automate:

• How to make it worth the effort?

• Home work

• Testing effort calculation

Page 9: Automated testing basics for test engineers

Entry poll (answer as you understand)

•Why do you need to test the software ?

•Why you need to automate the tests?

• If 5-years old child ask you what is a programming language, what would you say?

• If the same 5-years old child ask you what the test engineers are needed for, what would you say?

• Your test that was successful now fails. Is it good or bad?

•What is a procedure (function, method, message,…) in programming languages?

• Give the examples of the test automation in the real life

•What is HTML?

• If you have a Web page address like http://go.microsoft.com/fwlink/?linkid=55424,what parts can you see there?

•What does it mean if your Web Browser answers to your request for some page with the following message: 404 Page Not Found? What means 404? Can there be other numbers?

•What main parts of Web page definition in HTML file you know?

Page 10: Automated testing basics for test engineers

Day 1 of 6: Testing and quality

•Why to test?

• To ensure that application meets some minimal quality criteria

• To ensure that application fails where it should and in a good way

• To avoid regressions over time

• To finally understand what the system do if requirements are poor

•Why not to test?

• Testing costs money

• Testing never guarantees that application is bug-free

• Badly planned testing can make wrong impression that application is ok while it is not

• “Do it to make test passed”: objectivity of measures

Page 11: Automated testing basics for test engineers

Day 1 of 6: Automation: When? Why? How Much?

• Why to automate:• Don’t run the same tests for every build until get crazy

• Execute multi-user, stress and load test scenarios

• Exclude “human factor”

• Why to don’t automate:• High preparation costs: automated test is a program, that should be designed, developed and

tested itself

• High support costs: If system under test changes it is highly probable that tests should be changed as well. If the changes are significant, the changes costs may be comparable to the preparation costs.

• Questionable relevancy if no requirements are provided: If requirements are not clear (as it often happens) the UI of application under test will change again and again, so the tests will too.

• How to make it worth the effort• Have the stable requirements before creating the tests (if you can…)

• Predict the possible changes and parameterize the tests whenever needed (use PageObjectpattern etc.)

• Calculate the effort and decide if the automation is profitable

Page 12: Automated testing basics for test engineers

Day 1 of 6: Home work: Testing effort calculation and decision whether to automate

• Case 1• You team is developing a new social network site to be launched globally in 60 days

• Four be-weekly sprints are left each followed by a build to be tested

• You have the actual and full set of user stories and test cases.

• Manual testing of one build takes about 15 man/days

• Creating the automated tests coverage takes 20 day, and adopting for the next build takes 5 days

• You have just one test engineer available, who can do either manual or automation testing. She cannot work overtime.

• Case 2• You are developing a new handmade toys Internet shop based on popular Magento

platform. You should mainly change the design and add few content pages.

• You plan to finish the site in 3 weeks. You have a freelance test engineer available part-time per your request

• Two iterations’ results are planned to be presented to customer

• You expect that manual testing may take a week per version

• Automated tests may be created in 8 days, with 3 days needed to adopt for new version

Page 13: Automated testing basics for test engineers

Day 2 of 6: Agenda

• Check the home work

• From the very beginning: Programs = Algorithms + Data Structures (N. Wirth)• What is a program

• What is the data and how it gets together

• Code structures: Go Ahead, Do It Sometimes, Do It Again

• Think smaller: Functions and Recursions

• Simple algorithms: Make it works

• Objects all around• Code As You Think

• Inherit, Reuse, Morph

• A bit about terms

• In the real world • Frameworks: They are here to help us

• Event-driven development and user interaction

• Software As A Services: Work when you are asked for

• Home work• Objects hierarchy definition

Page 14: Automated testing basics for test engineers

Day 2 of 6: Programs = Algorithms + Data Structures

• What is a program: • Maybe looks too simple, but anyway..• Set of instruction those are understandable by computer or can be automatically translated into

computer-understandable format, and the data to be processed by this instructions• Life example: Usage instruction for complex devices

• What is the data and how it gets together• Data is any information to be processed by computer to get some benefits to the user.• Examples: accounting records in financial software, site content to be retrieved from Web Server, new

post to be sent to Twitter, file with the image to be processed by image editor software

• Code structures: Go Ahead, Do It Sometimes, Do It Again• There are three main things we can we do with a set of instructions• Execute them one-by-one: Go to shop, buy potatoes, boil them• Do or skip depending on condition: Take an umbrella if it rains• Repeat until something happens or given number of times: Make a step until you arrive, Wash you

head twice.

• Think smaller: Functions and Recursions• Programs get too complex and big, so we need to divide them into parts• Here functions come: part of the program having specified inputs and outputs (interface)• They may be called methods, messages, signals, procedure, subprograms depending on your language• Functions can call other functions and themselves. It is called recursion.

• Simple algorithms: Make it works• Let’s practice!

Page 15: Automated testing basics for test engineers

Day 2 of 6: Objects all around

• Program As You Think• Functions make programs simpler, but when there are thousands of them the chaos comes back• The program is simpler to understand if it mimics the way humans think• Humans always think of objects: Tree, House, Sun, Cat, Humanity or Honesty.• Object is an idea, that may have or may have not the real instances: instances of Dog exist, but

instances of Elf probably don’t.• Object represents the set of properties and possible actions to be performed by its instances.

For example the Car has model name, color and production year , and can go in a certain way• Even the simplest things like numbers or strings can be thought of as objects

• Inherit, Reuse, Morph• The objects are not isolated: they are always related in some way to other objects around: the

bird sits on the tree, the man eats the apple, the action produces the response• There are three main kinds of relations between objects: Encapsulation, Inheritance,

Polymorphism• Encapsulation, Inheritance, Polymorphism

• A bit about terms• Objects and Classes – often the abstract idea is called class, while the concrete instances called

objects• Properties are sometimes called fields, and actions are often called methods, messages, signals

etc.

Page 16: Automated testing basics for test engineers

Day 2 of 6: In the real world

• Frameworks: They are here to help us• Pure programming language is like a “thing inside itself”: it can do anything but nobody will

know about that• We need to communicate with the user, devices, network and other computers• There are lots of typical programming tasks somebody already solved better that we do: sorting,

compressing, images transformation, threads synchronizations etc.• Frameworks are the programming libraries already created by somebody else to be used by

other

• Event-driven development and user interaction• Models of user interface: Console and Graphical User Interface.• The Console model is like a turn-based game: System makes its move and passes to the user• The GUI model is event-driven: All we do is a response for some user activity. For example we

show the picture when user clicks on it

• Software As A Services: Work when you are asked for, wherever you are• Do you have a hospital, shoes factory, food warehouse, and auto repair station at home? Surely

you can, but if they are used rarely and up to different scale it is not profitable• You use services instead: go to the doctor, repair service, supermarket, and auto service.• Web Service is a software serving the remote requests from another software specified in

agreed protocol, performing some processing and returning the result .• Strictly, Web and Email servers are services as well as they communicate with browsers and

mail clients respectively.

Page 17: Automated testing basics for test engineers

Day 2 of 6: Home work

• Objects hierarchy definition. Please draw a hierarchy of objects, with their sample characteristics (properties) and activities (methods) in one of the following areas:

• Vehicles

• Animals

• Alcohol drinks

• Computer games

• Numbers in mathematics theory

• (Anything else)

Page 18: Automated testing basics for test engineers

Day 3 of 6: Agenda

• Check the home work• Client-server approach

• Clients: in-place, convenient, specific• Servers: single center, full control• Intermediates: route the communication, translate the messages

• Basics of the Web• Basic terms• What is World Wide Web• How they communicate• World of browsers• Web Services: Web for machines

• HTML basics• How to deliver the imagination?• HTML basics: tags, documents, views

• HTML: nice and dynamic• Separating content and appearance: CSS• Adding dynamics: Java Script, DOM and events• Next steps: HTML5 and CSS3

• Home work• Search for HTTP request types definition• Simple site about yourselves with minimum 3 linked pages

Page 19: Automated testing basics for test engineers

Day 3 of 6: Client-server approach

• Distributed systems: Every component resides in the best location depending on its needs: The client near next to user, the server in high0bandwidth data center, intermediate where multiple data flows cross

• Clients: near to users, adopted to their needs, specific for the user environment. For example: Web payment system having native clients for Android, iOS (iPhone and iPad separately), Windows Phone, Mobile site and Desktop site. Every client provides the best user experience possible with their devices.

• Servers: single server or farm in special environment with high-speed network connection, real-time replacement, physical and electrical protection etc. Easy to monitor, maintain, and update.

• Intermediates: Servers may reside too far from client with slow network channels in between. So we may need to cache the intermediate data, route the communication into proper channel, aggregate the messages. Acts as a spinal brain for dinosaurs

Page 20: Automated testing basics for test engineers

Day 3 of 6: Basics of the Web

• Basic terms:• Client is a party requesting the information, usually on behalf of the user. Example: Web

browser• Server is a party providing the requested information by request from. Example: Email server• Proxy is an intermediary processing and re-sending the requests from Client to the Server and

responses back, possibly providing additional encryption, routing or authentication services

• What is World Wide Web: Global network of interconnected computers using HTTP-based protocol for exchanging the data. The data and data protocols may vary, for example HTML pages or images over HTTP, SOAP for services communication, SMTP for EMailssending etc.

• How they communicate: HTTP is basically stateless protocol of request-response kind. It means the client should sent a separate request to the server each time any information is to be obtained. It has state management, push and streaming extensions however.

• World of browsers: There are lots of competing software implementing both server and client sides of the web. Most known and visible are the Web browsers intended for showing the hypertext pages, images and other visual content to users. The concurrency brings up certain incompatibilities in a way different browsers interpret and display the content.

• Web Services: Web for machines. Due to its comprehensibility and flexibility the HTTP and Web are highly suitable for exchanging the data between computer systems when no ultra performance is needed. Example: REST protocol for remote database-like storages access.

Page 21: Automated testing basics for test engineers

Day 3 of 6: HTML basics

• How to deliver the imagination? Despite there are lots of format to present the multimedia content (PDF, Word, SVG etc.) the most popular now is the HTML (Hyper Text Markup Language) and related CSS (Cascaded Style Sheets) and JavaScript technologies

• HTML basics: tags, documents, views.

• HTML document is a description of how the multimedia information should be presented to user. Documents consist of the tags making its structure. The tag is a named section that may or may not be built into other tags and have the attributes and inner content.

• As a result of its interpretation the content is displayed in a browser view. Browser can have simultaneously multiple views displayed in the different windows or in the same windows (as frames). These views often called windows themselves.

Page 22: Automated testing basics for test engineers

Day 3 of 6: HTML nice and dynamic

• Separating content and appearance: CSS• The typical HTML document has two goals: define what to show to user and how to show it.

• Often we need the same content to be displayed in different ways over time, on different devices, in different countries etc.

• CSS is a recommended declarative way to separate the definition of style (appearance) of the document from the content to be displayed with this style

• CSS supports wide range of static properties (color, font, matrix transformations ,…) as well as basic dynamic behaviors (hover behaviors, transitions etc.)

• Adding dynamics: Java Script, DOM and event• Modern users wants more: Sites should be interactive, adaptive and “sexy”

• Browsers provide programmatic access to every element displayed and ability to change them any time

• JavaScript is a full-functional scripting language executed inside the browser and utilizing the browser DOM model

• Next steps: HTML5 and CSS3• More multimedia: Audio, Video, SVG, …

• More structured representation

• More programming possibilities: Local Storage, database, HTTP requests,...

• More compatible (coming soon )

Page 23: Automated testing basics for test engineers

Day 3 of 6: Home work

• Search for HTTP request types definition

• Simple site about yourselves with minimum 3 linked pages

Page 24: Automated testing basics for test engineers

Day 4 of 6: Agenda

• Check the home work

• Selenium basics• Selenium IDE: Click, save, generate

• Selenium Server: Here or there – at your command

• Drivers: Make browsers do what you need

• Tests code: .NET approach

• Selenium continued• Selenium Grid: scale your test as needed

• Make your framework: just what you need, just how you wish

• Page Factory pattern implementation

• Data-driven testing

• Selenium tips and tricks

• Homework• Create a short features and price comparison table based on Internet sources for:

• Try the Selenium IDE

Page 25: Automated testing basics for test engineers

Day 4 of 6: Selenium basics

• Selenium IDE: Click, save, generate• + Easy to create basic test scripts• + Export to most popular programming languages• - Only in Firefox• - No conditions or loops support

• Selenium Web Driver Client: Program it yourself• + Set of libraries for automating Web browsers• + Supports different most popular languages and platforms• - The scripts should be created manually (or exported from Selenium IDE)• +++ Allows directly executing the JavaScript inside the browser

• Selenium Server: Here or there – at your command• Optional intermediary hosting the browser drivers • Processing requests from local or remote clients

• Browser Drivers: Make browsers do what you need• Can be run standalone from client or inside the Selenium Server• Supported for most popular browsers• Not fully featured on all platforms

• Tests code: .NET approach• See examples

Page 26: Automated testing basics for test engineers

Day 4 of 6: Selenium continued

• Selenium Grid: scale your test as needed

• Cloud-based platform for on-demand scaling and configuring the distributed Selenium tests

• Not in scope of today’s demo.

•Make your framework: just what you need, just how you wish

• Why standard is not enough: Selenium API is not very advanced or flexible, and is quite Java patterns’ oriented

• Want to write less code and make it clearer

• Let’s see a real-life example

• Page Factory pattern implementation

• Why we need it: Object under test knowing its structure

• Example of implementation: Simple object knowing its place

• Another ways: Properties for elements with automatic binding

• Data-driven testing:

• Use your favorite language’s data access tools

Page 27: Automated testing basics for test engineers

Day 4 of 6: Homework

• Create a short features and price comparison table based on Internet sources for:

• Selenium

• Microsoft Test Manager

• Test Complete

• HP Quality Center

• Try the Selenium IDE

• Setup Firefox browser if not installed

• Setup Selenium IDE plugin (http://docs.seleniumhq.org/download/)

• Record and play basic scenario of Google search

Page 28: Automated testing basics for test engineers

Day 5 of 6: Agenda

• Let it run!

• Simple chat site

• Server code: Works as it is

• Client smoke test: make sure it works at all

• Look form other sides: browsers around us

• Imagine here are lot of us: distributed testing

• Home work

• Add a bit of intelligence: auto response based on input

Page 29: Automated testing basics for test engineers

Day 6 of 6 : Agenda

• Selenium practice

• Selenium and unit tests integration

• Typical issues and solutions

• Multi-window Web applications

• Using JavaScript for complex cases

• Selenium tests in Java: Small example to feel the difference

• Exit poll

Page 30: Automated testing basics for test engineers

Exit poll• Software testing

• Give three main reasons to test software• On what stage is it better for test engineer to join the software development project?• What project documentation is most useful for the test engineer?

• Programming basics• What is a loop in programming?• What is the reason to pass parameters to methods, procedures or functions?

• Object-oriented approach• Describe what the class and the object are• What the events are used for?• What tools and means are usually provided by the software development frameworks?• Looking at the ATM (банкомат) as an object, please define it’s interface (properties, methods, events)

• Automated testing• What are the main benefits of software testing automation?• What are the main disadvantages of software testing automation?• Testing in what kinds of projects should usually be automated?• What is the data-driven testing?

• Selenium• What is Selenium IDE?• What browsers and platforms are supported by Selenium Remote Control?• What are the advantages and disadvantages of using Selenium as testing tool?• What regular expression special character(s) means "any character?"• What are the main components of Selenium testing tools?• Can tests recorded using Selenium IDE be run in other browsers?• What is the cost of Selenium test suite?• What are the advantages of using Selenium as testing tool?• What are the disadvantages of using Selenium as testing tool?• What other automated testing tools you know?

Page 31: Automated testing basics for test engineers

References

• Official links• Wikipedia: http://en.wikipedia.org/wiki/Selenium_(software)• Official site: http://docs.seleniumhq.org/• Selenium IDE: http://docs.seleniumhq.org/projects/ide/• Selenium RC: http://docs.seleniumhq.org/projects/remote-control/• Supported platforms: http://docs.seleniumhq.org/about/platforms.jsp#browsers• Documentation: http://docs.seleniumhq.org/docs/• Selenium grid: http://selenium-grid.seleniumhq.org/

• Q&As• http://www.seleniumguide.com/• http://www.slideshare.net/girichinna27/selenium-interview-questions

• Useful links• http://www.joecolantonio.com/2012/07/31/getting-started-using-selenium-2-0-webdriver-for-ie-in-

visual-studio-c/• http://www.software-testing.ru/events/864-programming-for-testers-new• http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/17f30113-8308-4684-86d8-

a27d437ec56d• http://habrahabr.ru/company/yandex/blog/158787/• https://code.google.com/p/selenium/wiki/PageObjects• http://selftechy.com/2011/03/18/selenium-setting-up-selenium-eclipse• www.w3schools.com/ - learning stuff for HTML, CSS, JS• Lots of relevant information on stackoverflow, softwaretesting.ru etc. Just google it!

Page 32: Automated testing basics for test engineers

Contact us!

Address:03056,24, Polyova Str.,Kyiv, Ukraine

Phone:+38 044 457-88-56Email:[email protected]

• Oleksandr Turevskiy

• +38 050 3239722

[email protected]