[go: up one dir, main page]

0% found this document useful (0 votes)
144 views161 pages

A4Q Selenium Tester Foundation-1

A4q selenium

Uploaded by

urvashi4301
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views161 pages

A4Q Selenium Tester Foundation-1

A4q selenium

Uploaded by

urvashi4301
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 161

This page is intentionally blank.

Introductions and Objectives

© A4Q Copyright 2018 1

The Main Topics Covered

1. Test Automation Basics


2. Internet Technologies for Test Automation of Web
Applications
3. Using Selenium WebDriver
4. Preparing Maintainable Test Scripts

© A4Q Copyright 2018 2

1
Business Outcomes

STF-BO1: Correctly apply test automation principles to


build maintainable test automation solution
STF-BO2: Be able to choose and implement correct test
automation tools
STF-BO3: Be able to implement Selenium WebDriver
scripts that execute functional web application
tests
STF-BO4: Be able to implement maintainable scripts

© A4Q Copyright 2018 3

It‘s Your Course

• Please join in
 Ask questions
 Make comments
 Share experiences
 Second opinions and disagreements welcome
• Why are you here?
• What do you want to learn, discuss, and teach?

© A4Q Copyright 2018 4

2
Acronyms (1)

AKA: Also Known As


API: Application Programming Interface
CERN: European Council for Nuclear Research (French)
CI: Continuous Integration
CSS: Cascading Style Sheets
DOM: Document Object Model
GUI: Graphical User Interface
HTTP: Hyper Text Transfer Protocol
ISTQB®: International Software Testing Qualifications Board
KDT: Keyword Driven Testing
REST: Representational State Transfer

© A4Q Copyright 2018 5

Acronyms (2)

ROI: Return on Investment


SDLC: Software Development Life Cycle
SOAP: Simple Object Access Protocol
SUT: System Under Test
TAA: Test Automation Architecture
TAE: Test Automation Engineer
TAS: Test Automation Solution
TCP: Transmission Control Protocol
UI: User Interface
W3C: World Wide Web Consortium

© A4Q Copyright 2018 6

3
Chapter 1
Test Automation Basics

© A4Q Copyright 2018 7

Terms to Remember

architecture pesticide paradox


capture/playback technical debt
comparator testability
exploratory testing test harness
fault attack test oracle
framework testware
hook

© A4Q Copyright 2018 8

4
Chapter 1
Test Automation Basics
Section 1: Test Automation Overview

© A4Q Copyright 2018 9

Learning Objectives

STF-1.1 (K2)
Explain the objectives, advantages,
disadvantages, and limitations of test automation

© A4Q Copyright 2018 10

10

5
What is Test Automation

• For our purposes, test automation is automatic, tool-based execution of


functional tests
• Automation usually simulates a human executing a test manually
• While execution is automated, analysis, design, and implementation are
usually still manual
• Automation requires much to support it, including:
• The environment the tests run in
• One or more specialized tools and test harnesses
• Code libraries of functionality to invoke
• Scripts to run
• Logging and reporting frameworks to evaluate the results

© A4Q Copyright 2018 11

11

Objectives of Test Automation

• Improve the efficiency of testing by reducing the cost of


each test run
• Test more and other things than we might be able to
manually test
• Reducing the amount of time needed for running tests
• Being able to push more testing earlier in the SDLC to
reduce the time defects are in the code
• Increasing the frequency of being able to run the tests

© A4Q Copyright 2018 12

12

6
Advantages of Automation
• Running automated tests may be more efficient that running them manually
• Perform some tests that cannot be performed at all or easily manually
• Reduce time needed for test execution allowing us to run more tests per build
• Increase the frequency that tests can be run
• Free up manual testers to test more interesting and complex manual tests
• Fewer mistakes made by bored or distracted manual testers
• Tests can be moved earlier in the process (e.g., placed on the continuous build machine to run
unit, component, and integration tests automatically)
• Give quicker feedback on system quality and allow defects to stay in the software less time
• Tests can be run outside of normal business hours
• Automated tests are repeatable, we can ensure that a test was run correctly (as compared to a
bored manual tester skipping steps and ignoring warning signs)
• Increased confidence in the build

© A4Q Copyright 2018 13

13

Disadvantages of Automation (1)

• Additional costs (including high startup costs)


• New technologies must be mastered by test group which may not have the
needed expertise
• In worst cases, complexity may become overwhelming
• Unacceptable growth where automation becomes larger than SUT
• Development class skills needed on test team or providing a service to the
test team
• Considerable maintenance of tools, environments, and test assets required
• Technical debt is easy to add, difficult to reduce
• Automation requires all the processes and disciplines of software
development

© A4Q Copyright 2018 14

14

7
Disadvantages of Automation (2)

• Concentrating on automation can make testers forget about risk


management for the project
• The pesticide paradox is increased when automation is used since
exactly the same tests are run each time
• Automation failures are often not SUT failures; they are in the
automation itself (false positives)
• Without clever programming in tests, tools are literal minded and
stupid; testers are not
• Tools tend to be single threaded – that is, they are only looking for one
outcome to an event when there are actually many possible outcomes
that may occur

© A4Q Copyright 2018 15

15

Limitations of Automation (1)

• Unrealistic expectations by management which often drives the


automation in the wrong direction
• Short term thinking which can destroy an automation project; only by
thinking long term can the automation program succeed
• Organizational maturity is required to succeed; automation based on poor
testing processes only delivers bad testing faster (or maybe even slower)
• Some testers are perfectly happy with manual testing and do not want to
automate
• Automation test oracles may be different than manual test oracles,
requiring they be identified
• Not all tests can or should be automated

© A4Q Copyright 2018 16

16

8
Limitations of Automation (2)

• Manual testing will still be required (exploratory testing, fault attacks,


etc.)
• Manual analysis, design, implementation are still likely to be manual
• Human beings find most bugs; automation can only find what it is
programmed to find
• False sense of security when large numbers of tests are run but few
failures discovered
• Technical problems for the project when sitting on the bleeding edge of
tools and techniques
• Require cooperation with development which can create inter-
organizational issues

© A4Q Copyright 2018 17

17

Example (1)

Automation can be a game changer to an organization.


One of my first big test automation successes was!
The business application I automated was very popular
in Europe, despite the fact that it was built in the US.
Our process before automation was to build and test it
in English. Upon US release, the application was sent to
several places in Europe to be translated into French,
German, Italian and Spanish. Six months after US
release, the translated application was released in
Europe. Unfortunately, the application was not
professionally tested after translation so the European
versions were full of bugs. [Continued next slide] The tower of Babel

© A4Q Copyright 2018 18

18

9
Example (2) (cont.)

My automated testing was written in English. However, by creating a


loadable GUI object properties map, I was able to create English, French,
German, Italian and Spanish versions of the map. Translation of the
resource strings was done in Europe as before, but done concurrently with
application development and sent to us in the US. We created five
separate builds of the system at our facility, each in a different language.
My automation could test each of the four globalized builds as easy as it
could the English version, simply by loading in the globalized properties
map. That meant that we could do full testing and then ship GA all over
the world at once, at a savings of over $1,000,000 and six months of
market time. Customer satisfaction in Europe soared, and sales jumped.
That was a game changer.

© A4Q Copyright 2018 19

19

Chapter 1
Test Automation Basics
Section 2: Manual vs. Automated Tests

© A4Q Copyright 2018 20

20

10
Learning Objective

STF-1.2 (K2)
Understand the relation between manual and
automated tests

© A4Q Copyright 2018 21

21

Automation Issues

• Early versions of automation tools had very high failure rates


• Their main problem was they didn’t model testing correctly
• Every test was run exactly the same every time
• Treated testing as low skill task (i.e., any monkey can do it)
• Change to the GUI happens often, breaking the scripts
• In fact, each test run manually triggers many instantaneous tester
decisions; takes a lot of intelligence to run
• Test scripts, at their most basic, contain three columns
• An abstract task to do
• The data to use for the abstract task
• The expected behavior

© A4Q Copyright 2018 22

22

11
Context and Reasonableness

• The manual script by itself is not very useful


• It must be integrated with a manual tester to add value
• The manual tester adds
• Context: an understanding of the context of the system, when, where,
how, and what needs to be done
• Reasonableness: did what the system did, and the time it took make
sense in the context we are in?
• Automated tools and recorded scripts are dumb: a tiny sense of context and
little reasonableness
• However each automation tool is—at its heart—a programming language
• Developers use the programming language to add context and
reasonableness to the scripts

© A4Q Copyright 2018 23

23

Programming Required

• Functional automation can only succeed when the intelligence of the


manual testers is added to scripts via programming
• This requires
• Analysis as to what is actually happening in the test
• Design of how to solve the issues raised
• Implementation using tools and callable libraries
• Documentation
• Maintenance when change occurs
• An automated script is a program that is written to test another
program (like shooting a bullet to try to hit another bullet)

© A4Q Copyright 2018 24

24

12
Manual vs. Automated Tests
• Not all tests can or should be automated
• A business case should be made before automating a test
• Does this test need to be run often enough to add value?
• How often will maintenance be needed?
• Can we understand the context and reasonableness needed?
• Is the dynamic thinking of the manual tester essential to this test?
• Exploratory testing
• Fault attacks
• Is there a good way to automate the evaluation of this test?
• Highly visual results
• Something that cannot be measured through the tool
• Does there need to be a manual intervention in the test?
• Manual tests are not obsolete; some will still be needed

© A4Q Copyright 2018 25

25

Example (1)

Early in my career as an automator, I thought that the more


verifications I could do, the better. Each GUI object on each
screen had maybe 35-45 different properties that my tool
could see. “Why not test them all”, I asked! We can make the
automation much, much better than the manual testing. So I
created verification points for everything; every property that
I could capture, figuring that every change had meaning, and I
would look for each.
As you might guess, this was an abject failure. In almost every
run of the automation, I got dozens of spurious failures that
meant nothing at all. [Continued next slide]

© A4Q Copyright 2018 26

26

13
Example (2) (cont.)

The developer moved an object one pixel over. FAIL! The


developer changed the color of a background slightly. FAIL!
The developer changed a label. FAIL! The developer changed
the order of a menu. FAIL!
What I quickly learned was to verify only those things that a
manual tester cared about. How did they determine pass or
fail? I would follow the same criteria. I developed a theory I
call “Test by Eye.” Rarely would I let the tool dictate what I
was going to verify throughout the test. If a manual tester
does not care about something, you should not either as a
test automator, unless there is a business value to it.

© A4Q Copyright 2018 27

27

Chapter 1
Test Automation Basics
Section 3: Success Factors

© A4Q Copyright 2018 28

28

14
Learning Objective

STF-1.3 (K2)
Identify technical success factors of a test
automation project

© A4Q Copyright 2018 29

29

How to Succeed

• Automation will not succeed by accident


• In order to succeed, an organization needs the same things that make
any software project succeed
• A long-term plan that is aligned with the business needs
• Good management and stark attention to detail
• Process maturity
• A formalized architecture and framework for automation
• Adequate training in both test and development engineering
• The ability to create and use good documentation
• Nothing can guarantee success, but lacking the above can certainly push
you towards failure

© A4Q Copyright 2018 30

30

15
Testability

• Automation is difficult to succeed if done on an island

• Getting buy-in and help from development can really help success

• An SUT that is designed for testability can help


• There are several different levels of interface for automation

• The GUI level (often brittle and failure prone)

• Application programming interface (API) for public and protected use

• API private use interfaces (hooks)

• Protocol level (HTTP, TCP, UD, etc.)

• Service level (SOAP, REST, etc.)

• The lower on that list, the less brittle and more robust will the automation likely to be

© A4Q Copyright 2018 31

31

Success Factors (1)

• Management which has been educated to understand what is


and is not possible (unrealistic expectations by management is
one of the biggest reasons for software test automation projects
to fail)
• A development team for the SUT(s) that understands automation
and is willing to work with the testers
• SUT(s) that are designed for testability
• Developing a business case for the short, medium and long term
• Having the right tools to work in the environment and with the
SUT(s)

© A4Q Copyright 2018 32

32

16
Success Factors (2)

• The right training, for both test and development tasks


• Having a well-designed—and well documented—architecture and
framework to support the individual scripts (the Advanced Test
Automation Engineer syllabus call this the TAS (test automation
solution))
• Having a well-documented test automation strategy that is
funded and accepted by management
• A formal and well-documented plan for maintenance of the
automation
• Automating at the right interface level for the context of tests
necessary

© A4Q Copyright 2018 33

33

Example

Getting buy-in from management and development can help an


automation project to succeed. Without that buy-in, an automation
team is not likely to get any testability features in the SUT.
I had a development team once which was not only not supportive,
they were downright hostile.
I was told by the development manager that testing
was not important, and that they would never help
with any testability features in the SUT. [Continued on next
slide]

© A4Q Copyright 2018 34

34

17
Example (2) (cont.)

Indeed, it seemed like they went out of their way to make it hard to
automate the SUT. That included using third-party controls that my tool
did not understand, refusing to use internal naming conventions that my
tool could read, and making so many tiny changes that caused my
automated tests to fail after almost every build.
The project failed “bigly.” And, as I left the project, I wrote a post-mortem
document that explained why in full detail and five part harmony and
delivered it to management.
When I saw that development manager a few years afterwards at a
conference, he blamed me for assassinating his career.
Can’t we all just get along?...

© A4Q Copyright 2018 35

35

Chapter 1
Test Automation Basics

Section 4: Risks and Benefits of Selenium


WebDriver

© A4Q Copyright 2018 36

36

18
Learning Objective

STF-1.4 (K2)
Understand risks and benefits of using Selenium
WebDriver

© A4Q Copyright 2018 37

37

Selenium WebDriver
• A programming interface for developing Selenium scripts
• WebDriver supports the following languages
• C#

• Haskell

• Java

• JavaScript

• Objective C

• Browsers supported by WebDriver


• Chrome (chromedriver)

• Internet Explorer (IEDriverServer.exe)

• Edge (MicrosoftWebDriver.msi)

• Firefox (geckodriver)

• Safari (safaridriver)

• HtmlUnit (HtmlUnit driver)

© A4Q Copyright 2018 38

38

19
Benefits of Selenium WebDriver

• Test execution is consistent and repeatable


• It is well-suited for regression testing
• It can catch UI-level problems that unit and API-level tests would
miss
• It is open source, so lower up-front investment
• It allows for quick browser compatibility testing
• Different language bindings means that a broader pool of testers
are available
• It requires that testers have a deeper understanding of the
underlying code, which is helpful on Agile teams

© A4Q Copyright 2018 39

39

Risks of Selenium WebDriver

• You can spend too much time on UI (browser-level) testing and


not enough on unit testing
• Full regression test execution times can become unwieldy for a CI
workflow
• If the UI is refactored, it can break a large percentage of the
automation tests, as compared to unit or API-level tests
• Manual testers tend to find more failures than does automation
• It is tempting to skip some important tests when they are more
difficult to automate
• It may not pay for itself, vs manual testing, if the web app does
not require many changes

© A4Q Copyright 2018 40

40

20
Example

RISK: One of our clients had 300 test cases automated without first building a proper
test automation framework (TAF) and using the Page Object Pattern. Before releasing
each new version they calculated the effort to update the test scripts and the effort to
write them from scratch, and each time both efforts where comparable.
ADVANTAGE: During the beginning period of test automation for major Polish e-
commerce site we observed following efforts of test automation:
• 1st TC – 6 man-days
• 2nd TC – 3 man-days
• 3rd TC – 1.5 man-days
We used Keyword Driven approach and the Page Object Pattern and were able to reuse
parts of already written scripts
NOTE: Advantages come with well-designed test automation architecture (TAA),
without it you have only the risks.

© A4Q Copyright 2018 41

41

Chapter 1
Test Automation Basics

Section 5:
Selenium WebDriver in Test Automation
Architecture

© A4Q Copyright 2018 42

42

21
Learning Objective

STF-1.5 (K2)
Explain the place of Selenium WebDriver in TAA

© A4Q Copyright 2018 43

43

TAA

• The test automation architecture (TAA) is a set of layers, services and


interfaces that are a large part of the test automation solution (TAS)
• The TAA consists of four layers that supply support for automation
• Test generation layer: supports manual and/or automated design of
test cases
• Test definition layer: supports the definition and implementation of
test cases and suites
• Test execution layer: supports both the automation execution and
logging/reporting of the results
• Test adaptation layer: provides objects and code to interface with
the SUT at various levels

© A4Q Copyright 2018 44

44

22
Example TAA

© A4Q Copyright 2018 45

45

The Advantage of Abstraction

• Selenium WebDriver is a component that fits into the test


adaptation layer
• The test adaptation layer permits a separation between the
SUT and the tests that are going to exercise it
• This allows the test cases to be more abstract, separated
from the SUT
• When the SUT changes, the functionality tends to remain
the same
• The test cases can remain the same (new tests must be
created against new functionality)
• The automated script may still need to change to physically
run against the SUT

© A4Q Copyright 2018 46

46

23
WebDriver

• WebDriver, as part of the test adaptation level, provides a programming interface to the SUT
• WebDriver facilitates communication with the SUT
• Allows visibility of current values in SUT
• Allows controllability of objects in SUT
• The automated script uses the API as a translation level as follows:
• The test case calls for a task to be completed
• The script calls an API in WebDriver
• That API connects to the appropriate object in the SUT
• The SUT responds as requested
• The success (or failure) is communicated back to script
• If successful, the next step in the test case is called in the script

© A4Q Copyright 2018 47

47

Example – Fragment of TAA with


Selenium WebDriver

© A4Q Copyright 2018 48

48

24
Chapter 1
Test Automation Basics
Section 6:
Reasons and Purpose for Metrics Collection

© A4Q Copyright 2018 49

49

Learning Objective

STF-1.6 (K2)
Explain the reason and purpose for metric collection
in automation

© A4Q Copyright 2018 50

50

25
Why Collect Metrics

• What gets measured gets done


• Automation is expensive in effort, time and resources
• Most organizations want a provable business case before starting
automation, requiring metrics
• Different metrics may be useful
• Usability of TAS by test analysts and automators
• Maintainability of the TAS
• Performance of the automation suite
• Reliability of the automation framework
• Unfortunately, many metrics collected in automation projects are less
than useful

© A4Q Copyright 2018 51

51

Problems for Metric Collection

• Automation is an investment which does not add value in the short


term; positive value only comes over the long term
• Trying to prove value during startup phase usually requires imaginative
accounting
• Management often insists that value be proven early causing TAEs to
offer illusion of value by automating large numbers of worthless tests
and running them even when not needed
• Trying to collect meaningful metrics may be distraction to a small team
just starting out
• Projecting the costs and value of running any given test in the future is
mostly guesswork
• Failures often occur due to automation itself, not SUT failure (yet still
take much effort to troubleshoot)

© A4Q Copyright 2018 52

52

26
Apples vs. Oranges
• Fixed automation costs tend to be very high
• Costs of a manual test can be determined fairly easily
• Because test case is abstract, once created only needs to change when major
changes to SUT occur
• Most future costs are simply time needed to run
• Few false positives because a knowledgeable tester runs it manually
• Costs of an automated test has far more variables
• Because test script is concrete, must be modified for almost any minor SUT change
• Future costs can be very high when changes are needed
• Trouble-shooting a false positive can be expensive in time
• Many of the costs of automation can only be estimated
• Such estimates tend to be manipulated to show what we want to show rather
than being realistic
© A4Q Copyright 2018 53

53

Meaningful Metrics

• Fixed costs to get the automation up and running


• Regression test effort that has been saved by the automation
• Effort expended by automation team maintaining, supporting, and
extending the automation
• Coverage in many dimensions
• Number of successful runs between failures
• Patterns of automation failures (looking for commonality of
problems by tracking root causes of failures)
• Number of automation failures found as compared to SUT failures
found by automation

© A4Q Copyright 2018 54

54

27
A Final Point

• Try to find metrics that help explain why the project is


important and valid
• Explain to management why there are difficulties recording
meaningful (and true) metrics
• Avoid the rosy scenarios that prove what a great value the
automation is right now
• Until the automation becomes mature, it simply will not
add that much value
• Getting caught fibbing about the actual value may get
the project killed

© A4Q Copyright 2018 55

55

Example

The manager of the test team understood automation really well, but he had made a deal with the
devil. He promised that if his team was given the budget, he would succeed at automating a very
tricky and difficult set of applications. In return for the budget, he promised an immediate (1 year)
return on benefit that was provable by a specified set of metrics.
The applications turned out to be harder to automate than he had thought. His automators were
excellent programmers, but did not understand testing. I was called in at the 8 month mark. A
review of the tests already written showed that almost all were worthless as far as managing actual
risk. Few really mitigated any important risks; instead they simply flashed and did stuff to show
that they were … doing stuff.
Given time, and some trained automators, I believe that automation program could have really
added value to the organization. By insisting
on immediate, provable value, however, management doomed
the automation program to failure. All of the necessities of
good testing were sacrificed to try to prove, prematurely, that
the automation was paying for itself.

© A4Q Copyright 2018 56

56

28
Chapter 1
Test Automation Basics

Section 7: The Selenium Toolset

© A4Q Copyright 2018 57

57

Learning Objective

STF-1.7 (K2)
Understand and can compare objectives of using
Selenium toolset (WebDriver, Selenium Server,
Selenium Grid)

© A4Q Copyright 2018 58

58

29
Selenium

• First introduced in 2004


• Originally an internal tool at ThoughtWorks, made open
source that same year
• Currently consists of four separate tools
• Selenium IDE
• Selenium WebDriver
• Selenium Grid
• Selenium Standalone Server

© A4Q Copyright 2018 59

59

Selenium IDE

• Add-on to Chrome and Firefox


• Easy to use
• Records user actions on web pages
• Replays recorded scripts
• Allows for adding verification points
• Has no variables, functions nor control flow structures
• Finds sensible locators
• During this training course we use Katalon Recorder instead
of Selenium IDE, which is very similar tool

© A4Q Copyright 2018 60

60

30
Example Selenium IDE

© A4Q Copyright 2018 61

61

Selenium WebDriver

• WebDriver is a framework allowing test scripts to control


web browsers
• Has APIs in many programming languages (e.g., Python,
Java, C#, Ruby)
• May need drivers for specific web browsers (downloaded
separately)
• This training course uses a reference implementation in
Python for Selenium WebDriver

© A4Q Copyright 2018 62

62

31
Selenium WebDriver Architecture

Web
Script Library WebDriver
Browser

• When a script creates an instance of WebDriver library


object, the library starts a WebDriver process which opens
the web browser
• The script calls library commands, and the library, through
WebDriver, sends the commands to the web browser

© A4Q Copyright 2018 63

63

Selenium Grid

• Enables running test scripts across many machines with many


configurations
• Allows distributed and simultaneous test execution
• Selenium Grid is very flexible
• Selenium Grid consists of one hub and several nodes
• The hub controls which test is run on which node
• Nodes in one grid may have many OSes, web browser types and
versions

© A4Q Copyright 2018 64

64

32
Example – Selenium Grid

Script with
Remote
WebDriver

Selenium Grid
Selenium
Grid Nodes
Hub

Linux Linux Windows Windows


Chrome Firefox IE Chrome

© A4Q Copyright 2018 65

65

Selenium Standalone Server

• Implements hubs and nodes for Selenium Grid


• Allows tester to run tests remotely even without a Selenium
Grid
• Written in Java, distributed as a jar file
• Must be run separately and configured properly (outside of
test scripts)

© A4Q Copyright 2018 66

66

33
Place of Selenium Standalone Server

Network

Selenium Web
Script Library WebDriver
Server Browser

• Selenium Standalone Server enables executing tests on a


web browser running on a different machine

© A4Q Copyright 2018 67

67

Chapter 2
Internet Technologies for Test
Automation of Web Applications

© A4Q Copyright 2018 68

68

34
Terms to Remember

CSS selector
HTML
tag
XML
XPath

© A4Q Copyright 2018 69

69

Chapter 2
Internet Technologies for Test
Automation of Web Applications
Section 1: Understanding HTML and XML

© A4Q Copyright 2018 70

70

35
Learning Objective

STF-2.1 (K3)
Understand and can write HTML and XML
documents

© A4Q Copyright 2018 71

71

HTML

• HyperText Markup Language


• Written in plain text with tags
• Tags specify contextual meanings of sections
of the document
• Tags identify how a browser should render
the document
• Credit given to Timothy Berners Lee for inventing Code above will generate this:

• In 2014, HTML 5 was released replacing 4.01


• HTML allows some variations which can affect
some browsers, so often XHTML is often used on
the web

© A4Q Copyright 2018 72

72

36
HTML Tags

• HTML elements usually have a start and end tag


• Tags are written inside angle brackets
• The end tag is usually the same as start but has “/”

• Some elements can be closed in the open tag

• A less strict browser might also accept

© A4Q Copyright 2018 73

73

Basic HTML Tags

© A4Q Copyright 2018 74

74

37
Lists and Tables

© A4Q Copyright 2018 75

75

HTML Forms

© A4Q Copyright 2018 76

76

38
XML

• eXtensible Markup Language


• Defines rules for formatting documents that is both machine and
human readable
• Can represent arbitrary data structures allowing data to be transported
and stored in readable format
• No predefined tags; author creates any tags desired
• Must be well-formed (each tag must be explicitly closed)
• Document always forms a tree structure

© A4Q Copyright 2018 77

77

XML Attributes

• Tags are formatted like HTML, but created as


needed
• XML supports attributes which may be added
to tags to further describe elements

• The same information may also be used as an


element instead of an attribute
• Attributes are not as flexible as elements
• Attributes cannot contain multiple elements
• Attributes cannot contain tree structures
• Attributes are not easily expandable

© A4Q Copyright 2018 78

78

39
XML has a Tree Structure
• The current node is any arbitrary node that we choose.
• All other relationships derive from the current node
• In the slide below, we have chosen “Bonnie Tyler” as the current node
• All relationships then refer to that node

• Each node can identify itself as self


• A parent node is one level higher in the hierarchy than the current node
• Each element node and attribute has exactly one parent
• The root has no parent node
• A child node is always one level below its parent in the hierarchy.`
• A sibling node is on the same level as the current node
• A sibling has same parent as current code
• An ancestor node is one in a direct path from the current node up through its parent, grandparent,
great-grandparent, etc.
• A descendent node is one in a direct path down from the current node in the hierarchy (i.e., a child, a
child of a child, etc.)

© A4Q Copyright 2018 79

79

Example XML Document (Partial)

© A4Q Copyright 2018 80

80

40
Chapter 2
Internet Technologies for Test
Automation of Web Applications
Section 2: XPath and Searching HTML
Documents

© A4Q Copyright 2018 81

81

Learning Objective

STF-2.2 (K3) Apply XPath to search XML documents

© A4Q Copyright 2018 82

82

41
Example XML document

© A4Q Copyright 2018 83

83

XPath Expressions

• Path expressions allow the automator to find specific node(s) to


operate on
• Expressions are similar to those used in navigating a folder system on a
computer

© A4Q Copyright 2018 84

84

42
Selecting Nodes

• Specific nodes can be selected using these path expressions

© A4Q Copyright 2018 85

85

Wildcards in XPath

• Wildcards can select XML nodes based on specified criteria

© A4Q Copyright 2018 86

86

43
Predicates

• Predicates are conditions that chosen elements must meet


• Predicates are surrounded by brackets [] and given after the element
name

© A4Q Copyright 2018 87

87

Operators in Predicates

© A4Q Copyright 2018 88

88

44
Useful String Functions

© A4Q Copyright 2018 89

89

Useful Links

• W3Schools offers free education on HTML, XML, XPath, CSS, etc.

• Free site to practice testing XPath expressions

© A4Q Copyright 2018 90

90

45
Chapter 2
Internet Technologies for Test
Automation of Web Applications

Section 3: CSS Locators

© A4Q Copyright 2018 91

91

Learning Objective

STF-3.3 (K3)
Apply CSS locators to find elements of HTML
documents

© A4Q Copyright 2018 92

92

46
Cascading Style Sheets

• CSS are used to define how HTML elements should be rendered


on a screen, a page or other media
• CSS can be used in HTML documents three ways
• An external style sheet, separate from the HTML pages
• An internal style sheet, within the <head> of an HTML file
• Inline, added directly to an element as an attribute
• When multiple CSS files are applied, the last one read is applied
• CSS is not considered a programming language; it is defined as a
style-sheet language
• A CSS rule-set consists of selectors and declaration blocks (see
next slide)

© A4Q Copyright 2018 93

93

A CSS Rule-Set

• Each selector points to an HTML element that you want to style


• A declaration block contains one or more declarations ended by semi-
colons

© A4Q Copyright 2018 94

94

47
CSS vs. XPath Selectors

• Both XPath and CSS may be used to select elements

© A4Q Copyright 2018 95

95

CSS Selector Example

© A4Q Copyright 2018 96

96

48
CSS Selectors – Work with Attributes

© A4Q Copyright 2018 97

97

CSS Selectors with Attributes Example

• Nodes can be selected in multiple ways using attributes

© A4Q Copyright 2018 98

98

49
CSS Selectors for Form Elements

© A4Q Copyright 2018 99

99

CSS Selectors Useful for Automation

© A4Q Copyright 2018 100

100

50
Chapter 3
Using Selenium WebDriver

© A4Q Copyright 2018 101

101

Terms to Remember

class attribute
DOM (Document Object Model)
function
ID
iframe
modal dialog
pytest
WebDriver
wrapper

© A4Q Copyright 2018 102

102

51
Chapter 3
Using Selenium WebDriver

Section 1: Logging and Reporting Mechanisms

© A4Q Copyright 2018 103

103

Learning Objective

STF-3.1 (K3)
Use appropriate logging and reporting mechanisms

© A4Q Copyright 2018 104

104

52
Running Scripts
• Test automation simulates a human tester running a test via the
keyboard and mouse
• A tester running a test has a pretty good idea what happened
• An automated script relies on logging to understand what
happened
• Python scripts may be programmed from scratch
• Alternately, existing frameworks may be used to run tests
• “unittest”
• “pytest”
• Testing frameworks reduce the amount of work needed
• For this syllabus, we have chosen to work with pytest because it works
quite well with Selenium WebDriver
© A4Q Copyright 2018 105

105

Running Tests with “pytest”

• “pytest” runs all test cases in the current directory and child
subdirectories below it
• Searches for test_*.py or *_test.py files
• From those files collects:
• test_* : functions outside of a class
• test_* : methods inside Test* classes (without an __init__ method)
• Run behavior depends on execution flags
• pytest : (no flag) runs all tests
• pytest –v : verbose mode showing full names
• pytest –q : quiet version, displays less information
• pytest --html=report.html : run test with report to the HTML file
(must have pytest-html module installed)

© A4Q Copyright 2018 106

106

53
Marks

• Marks can be used to apply metadata to test functions


• To always skip a test: use skip
@pytest.mark.skip

• To skip if a certain condition is met: use skipif


@pytest.mark.skipif(condition)

• To produce an expected failure, use xfail


@pytest.mark.xfail

• To perform multiple calls, use parameterize


@pytest.mark.parameterize(argnames)

© A4Q Copyright 2018 107

107

General Log Information

• GUI automation tends to fail more often than manual testing


• When a script fails, the test analyst running the automation needs to
determine:
• Is it a false positive where automation script/framework failed?
• Is it an actual SUT failure which must be investigated?
• Without good logging, can take lot of time to decide
• Logging often used to facilitate audit of automated testing
• Logged events often get put in stakeholder reports
• Different information may be logged
• All steps of test (useful for debugging)
• Warnings when unexpected results occur (e.g., sluggish timing)
• Actual failures

© A4Q Copyright 2018 108

108

54
Python Logging Library

• The script author can add logging calls to script to indicate:


• Certain events that have or are about to occur
• Data used in step
• Timing of events
• An event is described by a descriptive message
• Message may optionally contain variable data
• Each Python log message from logging library has level of severity (from
lowest to highest)
• debug: for diagnosing problems
• info: for checking that things work
• warning: something unexpected happened, potential problem occurred
• error: a serious problem occurred
• critical: a critical problem occurred

© A4Q Copyright 2018 109

109

Using the Logging Library

• Example of the code used to log an event


• Note that due to default logging level the info and debug messages
would not show up in log

© A4Q Copyright 2018 110

110

55
Assertions

• When running a test, expected results must be checked


• WebDriver can use assertions for checking results
• Assertion is a statement that a predicate (a condition) is expected to
always be true at that point in the code
• If assertion evaluates to false at run time, script throws an exception

© A4Q Copyright 2018 111

111

An Automated Step

• A step in an automated test case mimics the actions that a


manual tester would make
• With WebDriver, the following three actions occur
1. Locate a web element on a screen
2. Act on the web element
3. Ensure the correct thing happened
• Note that a failure could occur in any time
1. If the element is not found or is in unexpected state an exception will
be thrown
2. If attempt to act on the element fails, an exception is thrown
3. Can use assertion to check that the expected action occurred
• A manual tester does essentially the same three actions

© A4Q Copyright 2018 112

112

56
Reporting

• Reporting is not the same as logging


• Logging supplies information to the test analyst who ran a test script as
to what occurred during the run
• Reporting is supplying that—and other—information to stakeholders
of the project
• Automators need to understand
• Who the stakeholders are
• What information they want (need) to know
• How they want that information delivered
• Different stakeholders will want different information
• Where possible, reports should be bundled and delivered
automatically

© A4Q Copyright 2018 113

113

Report Contents

• Summary of what was tested


• Environments and configurations that were tested
• What occurred during the recent run
• Trends that are meaningful
• False positives and other issues
• Other metrics as agreed to with each stakeholder

© A4Q Copyright 2018 114

114

57
Chapter 3
Using Selenium WebDriver

Section 2: Navigate to different URLs

© A4Q Copyright 2018 115

115

Learning Objective

STF-3.2 (K3)
Navigate to different URLs using WebDriver
commands

© A4Q Copyright 2018 116

116

58
Different Browser Drivers

• Different browsers may have different behaviors


• Most web sites should be tested with different browsers
• Each browser is likely to need a specialized driver
• Each driver must be installed on the test workstation to allow the
test scripts to access the browsers
• Examples:
• Chrome (chromedriver.exe)
• Internet Explorer (IEDriverServer.exe)
• Edge (MicrosoftWebDriver.msi)
• Firefox (geckodriver.exe)
• Safari (safaridriver)
• HtmlUnit (HtmlUnit driver)

© A4Q Copyright 2018 117

117

The Driver Object

• The web browser is the main object to manipulate for testing


• The driver must first be created
• This creates the programming interface between the script and the web
browser
• A variety of functions and properties become available once the object
is created

© A4Q Copyright 2018 118

118

59
Opening a Browser Screen

• First instantiate a browser driver

• Enter in the desired URL

• Can check to make sure correct page opened

© A4Q Copyright 2018 119

119

Navigating the Browser

• Can drive backwards in the history

• Can drive forward in the history

• Can refresh the existing page

© A4Q Copyright 2018 120

120

60
Closing the Browser

• Can close the active window (tab)


• When the last window is closed, the browser quits

• Can close the browser and driver at the same time

© A4Q Copyright 2018 121

121

Chapter 3
Using Selenium WebDriver

Section 3: Change the Window Context

© A4Q Copyright 2018 122

122

61
Learning Objective

STF-3.3 (K3)
Change window context in web browsers using
WebDriver commands

© A4Q Copyright 2018 123

123

Changing Contexts

• Changing the script context can be done in two ways:


• Changing browsers
• Changing windows (tabs) within one browser
• The web browser does not need to have focus to be able to execute
Selenium WebDriver commands
• This enables running several tests simultaneously

© A4Q Copyright 2018 124

124

62
Opening Two Browsers

• Open the first browser

• Open the second browser

• Log the titles (to prove they opened)

• Close both browsers and destroy WebDriver objects

© A4Q Copyright 2018 125

125

Opening Multiple Tabs in Browser

• Opening multiple tabs in one browser can be done


• Different operating systems may have different techniques for
opening multiple tabs
• Thorough coverage is beyond the scope of this course
• One way is to execute JavaScript code

© A4Q Copyright 2018 126

126

63
Switching Between Tabs in a Browser

• First, get handles of all open tabs


• This property contains an array of handles to open tabs

• Change the active tab to a specific one

© A4Q Copyright 2018 127

127

Example of Window Handles

• Handles of a web browser’s windows are actually strings


• The following array represents the handles of a of web
browser with three open windows as defined in:

© A4Q Copyright 2018 128

128

64
Changing Frames

• Find a frame and switch to it

• Switch to a frame by ID when it is already known

• Switch to the parent frame

• Switch back to whole page (tab)

© A4Q Copyright 2018 129

129

Changing Browser Size

• Maximize the browser window

• Minimize the browser window

• Display the browser in full screen

© A4Q Copyright 2018 130

130

65
Chapter 3
Using Selenium WebDriver

Section 4: Capture Screenshots of Web Pages

© A4Q Copyright 2018 131

131

Learning Objective

STF-3.4 (K3)
Capture screenshots of web pages using WebDriver
commands

© A4Q Copyright 2018 132

132

66
The Value of Screenshots

• Manual testers interact with the GUI objects on a screen visually


• When a test fails, they can see exactly what the problem was
• Automated testers usually can’t see the test run
• Sometimes, it is useful to see the state of the screen
• When the automated test detects a failure
• When running a highly visual test where the pass/fail result depends on
the tester analyzing the screen visually
• When the testing might be audited for compliance
• When doing configuration testing on multiple systems
• An image of a failure in the log can reduce time needed to troubleshoot
the failure

© A4Q Copyright 2018 133

133

Dealing with Screenshots

• Automators must plan screenshots carefully


• Must avoid overwriting previous screenshots
• Need a unique folder to place them in
• Need an algorithm for naming them
• Two different screenshot scopes
• Taking a snapshot of the entire browser screen
• Taking a snapshot of a single element on a screen
• When writing to an HTML log, screenshots can be inserted directly into
the log

© A4Q Copyright 2018 134

134

67
Different Snapshots

• A screenshot of the entire browser window to file

• A screenshot of an individual element of the screen sent to


a file

© A4Q Copyright 2018 135

135

Other Screenshot Options

• Rather than create a file, you may want to create a base64


encoded string of an image
• This will be safe to stream (e.g., to a database record)

• You may also want to simply create a binary representation


of an image without sending to a file

© A4Q Copyright 2018 136

136

68
Chapter 3
Using Selenium WebDriver

Section 5: Locate GUI Elements

© A4Q Copyright 2018 137

137

Learning Objective

STF-3.5 (K4)
Locate GUI elements using various strategies

© A4Q Copyright 2018 138

138

69
Locating GUI Elements

• Operating on a GUI element using WebDriver requires that you find it on the
screen first
• A variety of functions are available: two main flavors:
• To find a single object: find_element_by_xx
• To find multiple objects: find_elements_by_xx
• Each of the above uses different locators
• HTML locators
• By the ID: by_id(id_)
• By the class: by_class_name(name)
• By the tag name: by_tag_name(name)
• XPath locators: by_xpath(xpath)
• CSS selectors: by_css_selector(css_selector)

© A4Q Copyright 2018 139

139

The Document Object Model (DOM)

• A browser models a web-page as a tree of objects called a DOM


• Platform and language neutral interface
• Allows programs and scripts to dynamically access and update a document’s
• Content
• Structure
• Style
• The DOM defines
• All HTML elements as objects
• The properties of all HTML elements
• The methods that can access all HTML elements
• The events that can affect all HTML elements

© A4Q Copyright 2018 140

140

70
The DOM for a Simple HTML Page

© A4Q Copyright 2018 141

141

Locate UI Elements by ID

• Refers to the HTML ID attribute

• A Python WebDriver locating example:

• Advantages
• Efficient
• Each ID should be unique in the HTML document
• Testers can (theoretically) add IDs to the SUT
• Disadvantages
• IDs may change dynamically when auto-generated
• IDs not appropriate for code used in multiple places
• Testers may not be allowed to modify the SUT

© A4Q Copyright 2018 142

142

71
Locate UI Elements by Tag Name

• Refers to HTML tag name attribute

• A Python WebDriver locating example:

• Advantage: if a tag name is unique to the page it is easier to


find
• Disadvantage: if the tag name is not unique to the page, you
may locate the wrong element

© A4Q Copyright 2018 143

143

Locate UI Elements by Link Text (1)

• Refers to the text placed in a clickable link


• In the following code, the bolded text is the link text

• Can be found by full or partial link text

© A4Q Copyright 2018 144

144

72
Locate UI Elements by Link Text (2)

• Advantages:
• Can find the element if unique to page
• The link text is visible to the user (in most cases), so it’s easy to
know what the test code is looking for
• Partial link text is slightly less likely than the full link text to change
• Disadvantages
• More likely to change than ID or class name
• Partial text may create more matches

© A4Q Copyright 2018 145

145

Locate UI Elements by XPath

• XPath (XML Path Language) can select nodes from an XML


document
• WebDriver can use XPath to find an XML node, and from
that, an element can be located
• Since HTML is a subset of XML, XPath can be used on it

© A4Q Copyright 2018 146

146

73
Absolute Path vs. Relative Path

• Can specify an absolute path: exact path to node


• Absolute path is brittle, likely to break when changed

• Relative path is more resistant to change

• Both of these example return the same field in the HTML


code on previous slide

© A4Q Copyright 2018 147

147

Locate UI Elements by XPath – Generic


Locator (1)

• Within an XPath string, you can look for ID, name, class, tag
name, etc
• Can create generic locator functions using XPath
• Pass in an attribute type to the function
• Pass a path string that specifies the attribute in it
• Generic functions reduce the amount of code you need to
write

© A4Q Copyright 2018 148

148

74
Locate UI Elements by XPath – Generic
Locator (2)

• A generic XPath locator

• Can be called for different attributes by changing the string


passed in

• Calling the generic function

© A4Q Copyright 2018 149

149

Locate UI Elements by XPath: Value

• Advantages
• Can find elements with no unique attributes (ID, class, name, etc.)
• Can use XPath in generic locators, using the different x_by_ strategies (by
ID, by class, etc.) as needed
• Disadvantages
• Absolute XPath code is fragile; may break with the smallest changes to the
HTML structure
• Relative XPath code can find the wrong node if the attribute or element is
not unique on the page
• XPath may be implemented differently on different browsers or not
natively supported (e.g., IE); extra effort will be required to run WebDriver
tests in those environments

© A4Q Copyright 2018 150

150

75
Locate UI Elements by CSS Selector

• Locating an element by using CSS selector syntax


• For example, in this HTML:

• You can use:

© A4Q Copyright 2018 151

151

Locate by CSS Selector: Value

• Advantage: if an element is unique to a page, you can


narrow where you look
• Disadvantage: if an element is not unique to a page, you
may locate the wrong element

© A4Q Copyright 2018 152

152

76
Locate via Expected Conditions (1)

• Selenium with Python bindings has an expected_conditions module that


does more than simply find WebElements
• It can be imported from selenium.webdriver.support
• Many convenient predefined conditions
• You can also create custom expected_condition classes
• These classes offer greater specificity than the locators mentioned
above
• Can wait for WebElement and for specific thing to happen
• Become visible or invisible
• Check for alert
• Become selected or unselected
• Etc.

© A4Q Copyright 2018 153

153

Locating via Expected Conditions (2)

• Some predefined conditions are:


• alert_is_present
• element_selection_state_to_be
• element_to_be_clickable
• element_to_be_selected
• frame_to_be_available_and_switch_to_it
• invisibility_of_element_located
• presence_of_element_located
• text_to_be_present_in_element
• title_is
• visibility_of_element_located
• We will discuss these more in section 4.2

© A4Q Copyright 2018 154

154

77
Chapter 3
Using Selenium WebDriver

Section 6: Get the State of GUI Elements

© A4Q Copyright 2018 155

155

Learning Objective

STF-3.6 (K3)
Get state of GUI elements using WebDriver
commands

© A4Q Copyright 2018 156

156

78
Get the State of UI Elements

• After locating a specific WebElement we often need to get information


from it
• Information can include:
• Visible/not visible
• Enabled/not enabled
• Selected/not selected
• Reasons for an automator to determine this info
• Ensure the state is as expected at a given point in the test
• Make sure a control is in a state that it can be manipulated as needed in
the test case (i.e., enabled)
• Make sure that after the control was manipulated, it is now in the expected
state
• Make sure that the expected behaviors are correct

© A4Q Copyright 2018 157

157

Common Properties and Accessors

© A4Q Copyright 2018 158

158

79
Get a Text Value

• Locate the desired WebElement


• Use text property to access the text

© A4Q Copyright 2018 159

159

Chapter 3
Using Selenium WebDriver

Section 7: Interact with GUI Elements

© A4Q Copyright 2018 160

160

80
Learning Objective

STF-3.7 (K3)
Interact with GUI elements using WebDriver
commands

© A4Q Copyright 2018 161

161

Interact with UI Elements

• Order of tasks when automating a WebElement


• Make sure the element is located (section 3.5)
• Make sure element is in correct state (section 3.6)
• Control the element to change its state as wanted
• On the GUI screen, each WebElement is a metaphor that can be
manipulated
• Type into text field
• Click on a button, link, image, etc.
• Select an item from a list
• Submit the form for processing
• May need to consider synchronization needs

© A4Q Copyright 2018 162

162

81
Working with Text Fields

• Locate the text field


• Ensure it is in right state (visible and enabled)
• Clear the existing text out of it
• Simulate typing in using keyboard

© A4Q Copyright 2018 163

163

Working with Clickable UI Elements

• Locate the WebElement


• Ensure it is enabled
• Determine if ‘clickable’ (uses expected_condition() method
discussed in chapter 4) to wait for synch

• Click on the WebElement

• If radio button, may verify that it is now selected

© A4Q Copyright 2018 164

164

82
Working with Checkbox Elements

• Checkbox is a clickable element


• However, final state depends on starting state
• If checked, click makes it unchecked
• If unchecked, click makes it checked
• Cannot blindly click on it; must know desired end state
• Good opportunity to add some intelligence through building an
aggregate function
• Algorithm:
• If we want it checked and it is not, click on it
• If we want it unchecked and it is checked, click on it

© A4Q Copyright 2018 165

165

Code for Checkbox

• Define a callable function


• Arguments:
• Checkbox to use: ‘element’
• Desired state (Boolean): ‘want_checked’

• To call function (and check the box):

© A4Q Copyright 2018 166

166

83
Working with Select Controls

• Select controls (dropdown list boxes) allow user to select one or more
items from a list
• Selection options include
• Search the HTML to find the item desired and then click() on it
• Select by an item value (select_by_value(value))
• Select all items that display matching text (select_by_visible_text(text))
• Select an item by index (select_by_index(index))
• Deselection options include:
• Deselect all items (deselect_all())
• Deselect by index (deselect_by_index(index))
• Deselect by value (deselect_by_value(value))
• Deselect by visible text (deselect_by_visible_text(text))

© A4Q Copyright 2018 167

167

Select Control’s Selections

• It is often useful to determine what item(s) are selected in a dropdown


list
• Return a list of all selected items (all_selected_options)
• Return the first selected (or only if a single select control)
(first_selected_option)
• See a list of all the options in the list (options)
• An aggregate function can make it easier to deal with a dropdown list

© A4Q Copyright 2018 168

168

84
Click on a Dropdown Option

• Define a callable function


• Arguments:
• The WebDriver object reference: ‘driver’
• The ID of the dropdown object: ‘dropdown_id’
• The ID of the desired option: ‘option_id’

© A4Q Copyright 2018 169

169

Working with Modal Dialogs

• A modal dialog pops up over a web screen


• Does not allow access to the web screen until closed
• Used
• To get specific information from user
• to have user perform certain task(s)
• Example on next slide
• After adding item to cart on an ecommerce site
• Allows choice between more shopping or checking out
• Shows more purchase options based on choice just made

© A4Q Copyright 2018 170

170

85
© A4Q Copyright 2018 171

171

Dealing with Modal Dialogs (1)

• All code for the modal dialog is actually placed in the HTML
of the invoking screen
• Working with modal dialog depends on finding modal
element in the HTML code
• In this ecommerce site, the ID for the modal element is
layer_cart
• Want to get a reference to this element

© A4Q Copyright 2018 172

172

86
Dealing with Modal Dialogs (2)

• Next task is to determine what you want to do on the modal


dialog
• In this case want to click on the Proceed to Checkout button

• Press the button

• Make sure you get to expected location (see next slide)

© A4Q Copyright 2018 173

173

Verify Destination as Correct

© A4Q Copyright 2018 174

174

87
Chapter 3
Using Selenium WebDriver

Section 8:
Interact with User Prompts in Web Browsers

© A4Q Copyright 2018 175

175

Learning Objective

STF-3.8 (K3)
Interact with user prompts in web browsers using
WebDriver commands

© A4Q Copyright 2018 176

176

88
User Prompt Dialog Boxes

• A user prompt is a modal dialog box generated by a web page


• Modal means you must close alert box before you can access the
browser main page
• Require special handling because they are not part of the browser page
• W3C defines three similar user prompts:
• Alert
• Confirm
• Prompt
• Since all three user prompts are very similar with substantially the same
behaviors, we will discuss alerts

© A4Q Copyright 2018 177

177

Working with an Alert

• This code will allow us to work with the alert


• We can capture the text in the alert so we can search for
words/phrases

• Two ways to close the alert dialog

© A4Q Copyright 2018 178

178

89
Chapter 4
Preparing Maintainable Test
Scripts

© A4Q Copyright 2018 179

179

Terms to Remember

fixture
persona
wrapper

© A4Q Copyright 2018 180

180

90
Chapter 4
Preparing Maintainable Test
Scripts
Section 1: Maintainability of Test Scripts

© A4Q Copyright 2018 181

181

Learning Objective

STF-4.1 (K2)
Understand which factors support and affect
maintainability of test scripts

© A4Q Copyright 2018 182

182

91
Intelligent Automation

• Manual testers will likely always test better than automation


• Automation can be written to simulate manual testers’ thinking
processes
• When a manual tester is directed to use a control, they think
• Does the control exist?
• Is the control visible?
• Is the control enabled?
• If all the above are true, they proceed to use the control
• They then verify that the control did what they expected
• This is useful algorithm for adding intelligence to the functionality of a
tool by creating wrappers around tool functionality

© A4Q Copyright 2018 183

183

Building Function Wrappers

• Example of a callable function for a checkbox


• Arguments to be passed in:
• The checkbox control to use
• The final state desired (checked/unchecked)
• The amount of time willing to wait for control to become available
• See algorithm on next slide
• It takes resources up front to build these wrappers, but they can reduce
false positives and enhance logging

© A4Q Copyright 2018 184

184

92
© A4Q Copyright 2018 185

185

Create Other Functions

• Code that is used repeatedly can be put in functions


• Even if you choose not to use an object-oriented approach
to the test code, you can still create functions
• Locator functions can be placed in a file called
locators.py
• Frequently performed actions (and error handling) can be
placed in a file called
helpers.py

© A4Q Copyright 2018 186

186

93
Use Relative Paths

• Web elements can be located using absolute paths or


relative paths
• Absolute paths can break if the web page UI is changed
• Relative paths are more robust, especially when the path
starts close to the desired web object
• Work with developers to ensure that the HTML is written
well and changes as rarely as possible

© A4Q Copyright 2018 187

187

Naming and Comments

• Global names (variables and constants) make test code


more readable
• Comments:
• Meaningful comments in the automation code
• Comments should explain why you are doing something: any
automator can see what you have done!

© A4Q Copyright 2018 188

188

94
Consistent Names

• Function/method/class names should be consistent


• There should be a consistent and logical naming approach,
e.g., two related functions should not be called

and

© A4Q Copyright 2018 189

189

Create Test Accounts and Fixtures

• Sharing email account and SUT accounts with other users


can introduce uncertainty (including manual testers)
• Email accounts, SUT accounts and fixtures should only be
used by the automation group
• Email accounts should not be tied to a specific user. A
generic account, e.g., qauser@example.com is preferable
• Make these accounts realistic to simulate real users
(including personas)

© A4Q Copyright 2018 190

190

95
Log Execution Progress

• The Python logging module facilitates diagnostic and


audit activities
• Rather than using print() statements, you can directed
logged outputs to a log file and/or the console
• The log file can give you a clear view of the navigation
performed and the state of the software during execution

© A4Q Copyright 2018 191

191

Logging Examples

• When you navigate to a login page:

• When you find the Create User modal:

• When you don't find expected text in an alert:

© A4Q Copyright 2018 192

192

96
Consistent File Names

• Use consistent file names that convey their place in the functional
hierarchy

• Rather than:
• Use:

© A4Q Copyright 2018 193

193

Unnumbered Files

• It’s tempting to number files based on execution order or to


reflect requirement mapping
• Numbering test files will make maintenance unnecessarily
harder
• Execution order can be handled by a class or a master file
which calls other files

© A4Q Copyright 2018 194

194

97
Chapter 4
Preparing Maintainable Test
Scripts
Section 2: Wait Mechanisms

© A4Q Copyright 2018 195

195

Learning Objective

STF-4.1 (K3)
Use appropriate wait mechanisms

© A4Q Copyright 2018 196

196

98
Why are Waits Needed?

• Manual testers have no need for waits


• They can see when an action occurs
• If it is within a reasonable amount of time, they move to the next
step
• If something took too long, they simply write an incident report if it
is repeatable
• Automation tools supply little context or reasonableness
• The automation writer needs to define what is reasonable
when the script runs

© A4Q Copyright 2018 197

197

Problems with Waits in Automation

• Automation tools are literal minded


• If told to wait 3 seconds, will fail at 3.001 seconds (no
reasonableness)
• Some automators use the worst choice mechanism:

• The sleep() function is always set for the worst possible case
and should not be used
• WebDriver with Python has two different waits:
• Implicit waits
• Explicit waits

© A4Q Copyright 2018 198

198

99
Implicit Waits

• Sets a wait in WebDriver object


• Once set, remains active until WebDriver object is destroyed
• Anytime a WebElement is addressed, WebDriver polls DOM
until object is found or time runs out

© A4Q Copyright 2018 199

199

Explicit Waits

• Sleep(n) is an explicit wait


• Other explicit waits are easy to use
• Different languages have convenient methods for creating waits
• Python defines a number of ExpectedConditions which simplify setting
explicit waits
• ExpectedConditions work with a WebDriver method called
WebDriverWait()

• This code makes calling waits very easy

© A4Q Copyright 2018 200

200

100
Defined ExpectedCondition Methods

• title_contains • title_is
• presence_of_element_located • visibility_of
• element_to_be_clickable
• visibility_of_element_located • staleness_of
• presence_of_all_elements_located • element_to_be_selected
• text_to_be_present_in_element • alert_is_present
• text_to_be_present_in_element_value
• frame_to_be_available_and_switch_to_it
• invisibility_of_element_located
• element_located_to_be_selected
• element_selection_state_to_be
• element_located_selection_state_to_be

© A4Q Copyright 2018 201

201

Explicit Wait Example

© A4Q Copyright 2018 202

202

101
Chapter 4
Preparing Maintainable Test
Scripts
Section 3: Page Objects

© A4Q Copyright 2018 203

203

Learning Objective

STF-4.3
(K4) Analyze GUI of SUT and use Page Objects to
make its abstractions

© A4Q Copyright 2018 204

204

102
Use Page Objects

• As noted earlier in chapter, we want to move complexity


from scripts further up into the Test Adaptation Layer of the
TAA
• A Page Object is a class, a module or other set of functions
which contains the interface to tested form or page
• Divide Test Automation Solution into layers
• Test Adaptation Layer is in the TAA, originally defined in the gTAA
• A Page Object is a part of Test Adaptation Layer
• The test automation script is in the Test Execution Layer

© A4Q Copyright 2018 205

205

Reasons to Use Page Objects

• Creates reusable code that can be shared by multiple test scripts


• Reduces the amount of duplicated code
• Reduces cost and maintenance efforts for test automation scripts
• Encapsulates all operations on the SUT’s GUI in one layer
• Gives a clear separation between the business and the technical parts
for the test automation design
• When change inevitably occurs, it gives a single point to repair all
relevant scripts

© A4Q Copyright 2018 206

206

103
Sample Code Not Using Page Objects

© A4Q Copyright 2018 207

207

Same Code Using Page Objects

© A4Q Copyright 2018 208

208

104
Example of Page Object

© A4Q Copyright 2018 209

209

Rules of Constructing Page Objects

• Page Objects should not contain business assertions nor


verification points
• Page Objects can contain technical verifications (e.g., has a
page been loaded successfully) and waits
• A Page Object does not need to cover whole page, it may
apply to only a section of a form
• Only Page Objects should contain Selenium functions

© A4Q Copyright 2018 210

210

105
Page Objects Example
Using an [XXXXX] page

© A4Q Copyright 2018 211

211

Page Objects Example

• We can extract 3 Page Objects from visible part of XXXXX


page:
• Header
• Category picker
• Rest of the page
• We can export and implement several operations from
header part, e.g.:
• Search
• Click logo
• Show about page

© A4Q Copyright 2018 212

212

106
Example

• Code snippet of a method of a Page Object

© A4Q Copyright 2018 213

213

Chapter 4
Preparing Maintainable Test
Scripts
Section 4: Keyword Driven Testing

© A4Q Copyright 2018 214

214

107
Learning Objective

STF-4.4 (K4)
Analyze test scripts and apply Keyword Driven Testing
principles to building test scripts

© A4Q Copyright 2018 215

215

Keyword Driven Testing (KDT)

• A natural extension of the Page Object Pattern


• Keyword are abstract, business-related terms describing a
functional task that a SUT is supposed to do
• The ‘what’ an SUT does rather than ‘how’
• KDT models the way a manual test works
• Non-technical test analysts define the keywords they need
based on what tasks need to be tested
• Technical test analysts (automators) create the functionality
behind the keywords and the framework to execute the
tests
© A4Q Copyright 2018 216

216

108
Keyword Driven Testing

• ISTQB® Definition:
A scripting technique that uses data files to contain not
only test data and expected results, but also keywords
related to the application being tested. The keywords are
interpreted by special supporting scripts that are called by
the control script for the test.

© A4Q Copyright 2018 217

217

Keyword/Action Word

• Keyword (action word) is an abstract business action or step of a test


case
• Modeling a manual test step, a keyword script will generally contain
three columns:
• The task to do (the keyword)
• The data to do it with (may need multiple columns here)
• The expected result if it works correctly
• The keyword is abstract; it does not contain specific physical actions on
SUT
• Keyword implementation (e.g., in a Page Object) contains the specific
actions on SUT

© A4Q Copyright 2018 218

218

109
Keyword Example

Action Test data


• High level:
• Make a wire transfer from the customer to the provider account as
a payment for purchased goods
Implicitly: the
Test data expected result
is for action
• Low level: to be successful
• Open the file “XYZ”
Implicitly: the
Action expected result
is the file opens
© A4Q Copyright 2018 219

219

Advantages of KDT (1)

• The test case design is decoupled from the SUT interface


• A clear distinction is made between the Test Execution, the Test
Abstraction, and the Test Definition layers
• An almost complete division of labor:
• Test Analysts design test cases and write scripts using keywords, data, and
expected results
• Technical Test Analysts (automators) implement keywords and the
execution framework needed to run the tests
• Reuse of keywords in different test cases
• Improved readability of test cases (they look pretty much like manual
test cases)
• Less redundancy (code refactored into single location)

© A4Q Copyright 2018 220

220

110
Advantages of KDT (2)

• Lower maintenance costs and effort


• If the automation is off line, a manual tester can execute the test manually
directly off the automated script
• Because keyword tests are abstract, the scripts using keywords can be written
well before the SUT is available for testing (just like manual tests)
• The previous bullet means that automation can be ready earlier and pushed
into functional testing and not just regression testing
• A few technical automators can support many Test Analysts building tests
making the architecture totally scalable
• Because the scripts are completely separated from the implementation level,
different execution tools may be used interchangeably

© A4Q Copyright 2018 221

221

Keyword Driven Testing in TAA


Here keywords
Here keyword are used in
scripts are test steps along
executed by the with data and
Python run- expected results
time tool

Here keywords
are implemented
Here keywords as business steps
are implemented
in Page Objects

© A4Q Copyright 2018 222

222

111
Things to Consider

• Fine-grained keywords allow more specific scenarios, but at


the cost of script maintenance complexity
• Allowing access to low-level actions increases flexibility but,
if tied to the GUI, it increases test maintenance
• Aggregated keywords can simplify initial development but
complicate maintenance
• Initial keyword design is important, but new and different
keywords will ultimately be needed, which implicates both
business logic and the automation functionality to execute it

© A4Q Copyright 2018 223

223

Implementation of KDT

• Top-down
• Write test case steps as you would write manual tests, and then
implement them in your tool
• These steps can be written by test analysts
• More cost-effective when many keywords have already been
implemented or when tests scripts are updated
• Bottom-up
• Record a script and then refactor it to KDT architecture
• Usually used at the beginning of test automation

© A4Q Copyright 2018 224

224

112
Tools for KDT

• Cucumber
• Robot Framework
• Katalon Studio
• Concordion
• HPE Unified Functional Testing

• Keyword Driven architecture can be implemented in many


programming languages

© A4Q Copyright 2018 225

225

Example of a KWD Tool

© A4Q Copyright 2018 226

226

113
Example of a KWD Test

© A4Q Copyright 2018 227

227

Appendix A (1)

class attribute: An HTML attribute that points to a class in a CSS style sheet. It can
also be used by a JavaScript to make changes to HTML elements with a specified
class
comparator: A tool to automate the comparison of expected results against the
actual results
CSS selector: Selectors are patterns that target the HTML elements you want to
style
Document Object Model (DOM): An application programming interface that
treats an HTML or XML document as a tree structure wherein each node is an
object representing a part of the document
fixture: A test fixture is a mock object or environment used to consistently test
some item, device, or piece of software

© A4Q Copyright 2018 228

228

114
Appendix A (2)

framework: Provides an environment for automated test scripts to execute;


including tools, libraries, and fixtures
function: A Python function is a group of reusable statements that perform a
specific task.
hook: An interface which is introduced into a system which is created
predominately to provide enhanced testability to that system
HTML (HyperText Markup Language): The standard markup language for creating
web pages and web applications
ID: An attribute that specifies a unique identification string for an HTML element.
The value must be unique within the HTML document
iframe: An HTML inline frame, used to embed another document within an HTML
document

© A4Q Copyright 2018 229

229

Appendix A (3)

modal dialog: A screen or box which forces the user to interact with it before they
can access the underlying screen
Page Object Pattern: A test automation pattern which requires that technical logic
and business logic be dealt with at different levels
pesticide paradox: A phenomenon where repeating the same test multiple times
causes it to find fewer defects
persona: A user profile created to represent a user type that interacts with a
system in a common way
pytest: A Python testing framework
tag: HTML elements are delineated by tags, written using angle brackets

© A4Q Copyright 2018 230

230

115
Appendix A (4)

WebDriver: The interface against which Selenium tests are written. Different
browsers can be controlled via different java classes, e.g., ChromeDriver,
FirefoxDriver, etc.
wrapper: A function in a software library whose main purpose is to call another
function, often adding or enhancing functionality while hiding complexity
XML (eXtensible Markup Language): A markup language that defines a set of rules
for encoding documents in a format that is both human-readable and machine-
readable
XPath (XML Path Language): A query language for selecting nodes from an XML
document

© A4Q Copyright 2018 231

231

116
Exam Questions
A4Q Certified Selenium Tester Foundation

English v1.1, Syllabus 2018

Participant

 Mr.  Ms. Date of birth:


Academic degree Year Month Day

First name Last name

Please note: Your name will be printed on the certificate as stated above. Please write clearly and in block letters.

Phone (business): /
Prefix Number

Mobile phone: /
Prefix Number

E-Mail address:
Please note: E-Mail address that iSQI will use to send you the exam results. Please write clearly and in block letters.

Postal address
Please note: iSQI will use the following address to ship the certificate unless it get sent to your training provider.
Please write clearly and in block letters.

if applicable: Company name

if applicable: Department

Address I:
Street, Zip code, City

Address II:
if applicable: PO box number Country

Member of:  ASQF -


 STEV Österreich (Austria)
ASQF membership no.

43-CSeT-F-Mock CERTiFYING PEOPLE Page 1 of 26


isqi.org
Exam Questions
A4Q Certified Selenium Tester Foundation

English v1.1, Syllabus 2018

Training provider

Training provider

Instructor

 I did not attend an accredited training.

 This is a re-sit exam for me.

Confirmation
(Please note: the confirmation is mandatory to conduct the examination)

 I hereby confirm the correctness of all my personal information as given above - especially the name and
contact details.

 I agree to have my personal data electronically stored and processed by the iSQI GmbH for general
reviewing purposes and for the purpose of issuing, administrating and recognizing certificates.
In addition, I hereby grant permission to the data being forwarded to the respectively responsible board.

By taking this exam you approve the iSQI Data Protection Clause. For further information please ask the
invigilator for the print-out of the Data Protection Clause or see www.isqi.org

Place, date Signature

Remarks

43-CSeT-F-Mock CERTiFYING PEOPLE Page 2 of 26


isqi.org
Exam Questions
A4Q Certified Selenium Tester Foundation

English v1.1, Syllabus 2018

Conditions of the exam

 The exam consists of 40 multiple choice questions.


 The number of correct answers is specified in the header of each question.
 There may be other appropriate answers to a question that are NOT listed in the answer
options.
 If more or less answers are ticked than there are correct solutions, the question is rated with 0
points.
 The selected answer(s) must be clearly indicated.
 Use a pen. Pencil may not be used.
 The total number of achievable points is 40.
 To pass the exam, at least 65% of the 40 points have to be achieved (= 26 points).
 Each of the questions is assigned to a "cognitive level" (K1, K2, K3 or K4) (for details, refer to
the Selenium Tester Foundation Syllabus).
 The exam lasts 60 minutes.
 Questions during the exam are not permitted and cannot be answered.
 Notes may only be made on the exam paper. Sufficient space for notes is provided on the last
pages of the paper.
 Notes will neither be read nor evaluated.
 The use of own documents or other resources (mobile phones, books, brought recordings,
calculators etc.) is not permitted.
 The exam paper may be returned before the end of the exam.
 The exam candidate must leave the exam room immediately after returning the examination
paper.
 You are not allowed to keep the exam paper. The exam paper must be returned.
 A form of identity with photo (personal identity pass, passport, driving license) must be
presented on submitting the exam paper.
 Results will be notified by e-mail, usually within one week.

 I have read and understood the above exam conditions.

Place, date Signature

43-CSeT-F-Mock CERTiFYING PEOPLE Page 3 of 26


isqi.org
Space for your notes
(notes will neither be read nor evaluated)

43-CSeT-F-Mock CERTiFYING PEOPLE Page 4 of 26


isqi.org
A4Q – Certified Selenium Tester Foundation

Question 1 of 40 | K1 | Number of correct answers: 1 | Maximum achievable credits: 1

What is capture/playback?

A. A function in a software library whose main purpose is to call another function often
adding or enhancing functionality
B. The interface against which Selenium tests are written. Different browsers can be
controlled via different java classes, e.g., ChromeDriver, FirefoxDriver, etc.
C. Representation of the layers, components, and interfaces of a test automation architecture,
allowing for a structured and modular approach to implement test automation.
D. A test automation approach, where inputs to the System Under Test (SUT) are recorded
during manual testing in order to generate automated test scripts that could be executed
later (i.e., replayed).

Question 2 of 40 | K1 | Number of correct answers: 1 | Maximum achievable credits: 1

Which of the following is the BEST definition of a test oracle?

A. A method of test effort estimation


B. A source to determine the expected outcome of a test case
C. A database of test data
D. A person who decides whether exit criteria of the test execution phase has been met

Question 3 of 40 | K2 | Number of correct answers: 2 | Maximum achievable credits: 1

Which two of the following five answers are advantages to using test automation?

A. Can perform some tests that we might not be able to run manually
B. Extra false positives can be collected and monitored
C. Allows the testers to concentrate on the technology rather than the risk
D. Reducing mistakes by bored or distracted testers
E. Technical debt is easier to add when automating

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 5 of 26
A4Q – Certified Selenium Tester Foundation

Question 4 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

What is the value of adding additional intelligence via programming to an


automated script?

A. Programming can add context and reasonableness to the test, mimicking a manual
tester’s thoughts
B. By adding programming, the programmer always reduces technical debt in the automation
project
C. Because an automated script requires more analysis and more design, maintenance
costs are less than a manual test
D. There is no actual need to add programming to a script; the tools work perfectly well
without it

Question 5 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

Which of the following is NOT an interface level that we could use automation for testing?

A. The GUI level


B. The service level
C. The protocol level
D. The abstract level

Question 6 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

Which of the following is a potential benefit that can be obtained by using Selenium
WebDriver?

A. Introducing a delay into the continuous integration process


B. Creating a set of automated regression tests
C. Increasing the defect detection effectiveness of tests
D. Producing an immediate, positive return on investment

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 6 of 26
A4Q – Certified Selenium Tester Foundation

Question 7 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

Into which part of the test adaptation layer does Selenium fit?

A. API
B. Services
C. GUI
D. None; Selenium fits into the test definition layer

Question 8 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

Consider the following metrics that might be useful, given in the syllabus:

i. Fixed costs to establish automation


ii. Regression test effort saved by the automation
iii. Effort expended supporting the automation
iv. Statement and decision coverage
v. Interface or data flow coverage
vi. Feature coverage
vii. Supported browser coverage

Which of these metrics would be useful for a Selenium automation project?

A. i, ii, iii, vi, and vii


B. i, ii, and iii
C. vi and vii
D. i, ii, iii, iv, v, vi, and vii

Question 9 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

Which of the following Selenium tools can run tests across multiple machines?

A. Selenium IDE
B. Selenium WebDriver
C. Selenium Grid
D. Selenium Standalone Server

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 7 of 26
A4Q – Certified Selenium Tester Foundation

Question 10 of 40 | K1 | Number of correct answers: 1 | Maximum achievable credits: 1

What is XPath?

A. A pattern that targets the HTML elements you want to style


B. A group of reusable statements that perform a specific task
C. A query language for selecting nodes from an XML document
D. An HTML inline frame, used to embed another document within an HTML document

Question 11 of 40 | K1 | Number of correct answers: 1 | Maximum achievable credits: 1

What is a tag in HTML?

A. An attribute of an HTML page, which contains the page author’s data


B. A problem with exchanging requests between a server and a client
C. A basic component of HTML
D. A specific design pattern of web pages

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 8 of 26
A4Q – Certified Selenium Tester Foundation

Question 12 of 40 | K3 | Number of correct answers: 1 | Maximum achievable credits: 1

Given the following code, which of the options best represents the resulting web page?

<html>
<body>
<h1>
Header Name
</h1>
<p>
paragraph text
</p>
<br/>
<!-- Here's the list:-->
<ul>
<li>first</li>
<li>second</li>
<li>third</li>
</ul>
</body>
</html>

A. Header Name
paragraph text
 first
 second
 third

B. Header Name
paragraph text
1. first
2. second
3. third

C. Header Name
paragraph text
 first
 second
 third

D. Header Name
paragraph text
Here's the list:
1. first
2. second
3. third

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 9 of 26
A4Q – Certified Selenium Tester Foundation

Question 13 of 40 | K3 | Number of correct answers: 1 | Maximum achievable credits: 1

Consider the following XML document:

<?xml version="1.0" encoding="UTF-8"?>


<weather>
<temperature UoM="F" city="New York">80</temperature>
<temperature UoM="F" city="Chicago">53</temperature>
<temperature UoM="C" city="Warsaw">30</temperature>
<temperature UoM="C" city="Berlin">24</temperature>
</weather>

Which of the following XPath expressions will find the value of UoM attribute for
temperature in New York?

A. //temperature[@city=“New York”]/text()
B. //temperature[@city=”New York”]/@UoM
C. //temperature[@city=”New York”]/@UoM/text()
D. @UoM[//temperature[@city=”New York”]]

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 10 of 26
A4Q – Certified Selenium Tester Foundation

Question 14 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

Consider the following HTML document:

<html>
<head/>
<body>
<form class="odd first">
User: <input type="edit" class="user" name="user" />
<br/>
Password: <input type="edit" class="password" name="password" />
<br/>
<button type="submit" name="login" class="big button">Log in</button>&nbsp;
<button type="submit" name="cancel" class="big button">Cancel</button>
</form>
</body>
</html>

Which HTML element or elements will be found with the following CSS selector?

.first > .big + .button

A. The “Log in” button


B. The “Log in” and “Cancel” buttons
C. The “Cancel” button
D. This CSS selector will not find any elements within this document

Question 15 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

Which of the following tags opens a new section?

A. <head>
B. <p>
C. <br/>
D. <div>

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 11 of 26
A4Q – Certified Selenium Tester Foundation

Question 16 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

Which of the following statements BEST captures the purpose of XPath in


Selenium automation?

A. To locate objects on a web page


B. To create XPath expressions
C. To describe the appearance of HTML on a screen
D. To describe a tree format

Question 17 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

Which of the following is NOT a way to use CSS in an HTML document?

A. External style sheet


B. Outboard style
C. Internal style sheet
D. Inline style

Question 18 of 40 | K1 | Number of correct answers: 1 | Maximum achievable credits: 1

What is a wrapper function?

A. A function in a software library whose main purpose is to call another function


B. A function providing an interface against which Selenium tests are written
C. A function providing an environment for automated test scripts to execute, including tools
D. A function in a software library whose main purpose is a programming interface for HTML
documents that allows external programs to interact with the browser page

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 12 of 26
A4Q – Certified Selenium Tester Foundation

Question 19 of 40 | K1 | Number of correct answers: 1 | Maximum achievable credits: 1

Which of the following is NOT a user prompt?

A. An alert
B. An iframe
C. A prompt
D. A confirm

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 13 of 26
A4Q – Certified Selenium Tester Foundation

Question 20 of 40 | K3 | Number of correct answers: 1 | Maximum achievable credits: 1

What will be the output of the execution of following piece of code from the file “question.py”?

import logging as log


log.basicConfig(level=log.INFO)
test_data = "Hello world"
log.info("Line 3")
log.debug("Line 4")
log.warning("Line 5")
log.error("Line 6")
assert test_data == "Hello world", “Wrong test data”
log.info("Line 7")

A. INFO:root:Line 3
WARNING:root:Line 5
ERROR:root:Line 6
INFO:root:Line 7

B. INFO:root:Line 3
WARNING:root:Line 5
ERROR:root:Line 6
Traceback (most recent call last):
File "question.py", line 8, in <module>
assert test_data == "Hello world", "Wrong test data"
AssertionError: Wrong test data
INFO:root:Line 7

C. INFO:root:Line 7
ERROR:root:Line 6
WARNING:root:Line 5
INFO:root:Line 3

D. INFO:root:Line 3
WARNING:root:Line 5
ERROR:root:Line 6
Traceback (most recent call last):
File "question.py", line 8, in <module>
assert test_data == "Hello world", "Wrong test data"
AssertionError: Wrong test data

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 14 of 26
A4Q – Certified Selenium Tester Foundation

Question 21 of 40 | K3 | Number of correct answers: 2 | Maximum achievable credits: 1

Given the following piece of code:

dr1 = webdriver.Chrome()
dr2 = webdriver.Firefox()
dr1.get(‘https://python.org’)
python_title = dr1.title
dr2.get(python_title)
dr2.get(‘https://perl.org’)

What will be the result of its execution (assume that the test environment is configured
correctly and all drivers are present)? Choose two:

A. Firefox will show https://python.org page


B. Chrome will show https://python.org page
C. Firefox will show https://perl.org page
D. The script will throw an exception
E. The outcome of this script cannot be determined

Question 22 of 40 | K3 | Number of correct answers: 1 | Maximum achievable credits: 1

Given a frame with an ID of "frameID", which of the following is/are the best line(s) of
code for changing the context of the test script back from the frame to the page that
the frame is in?

A. get('frameID').calling_page
B. element = driver.find_element_by_id('frameID')
element.back()
C. fr = driver.find_element_by_id('frameID')
driver.switch_to.frame(fr)
D. driver.switch_to.default_content()

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 15 of 26
A4Q – Certified Selenium Tester Foundation

Question 23 of 40 | K3 | Number of correct answers: 1 | Maximum achievable credits: 1

Take into account the following excerpt from a web page:

<a href=”https://python.org” id=”python”><img src=”python.png” /></a>

Which of the following answers contains the proper Python code for taking a screenshot
of the image python.png?

Assume that the variable driver contains the reference to the WebDriver object for the web browser dis-
playing the page from which the excerpt has been taken.

A. driver.find_element_by_id(“python.png”).screenshot(“my_new_pic.png”)
B. driver.find_element_by_id(“python”).screenshot(“my_new_pic.png”)
C. element = driver.find_element_by_id(“python”)
element.take_screenshot(“my_new_pic.png”)
D. element = driver.find_element_by_xpath(“a[@id=’python’]/img”)
element.take_screenshot(“my_new_pic.png”)

Question 24 of 40 | K3 | Number of correct answers: 1 | Maximum achievable credits: 1

Given a checkbox with an ID = "checkbox1", which line(s) of code will get the Boolean
value for the selected state of the checkbox?

A. element = driver.find_element_by_id('checkbox1')
cb_state = element.is_selected()
B. element_state = element('checkbox1').is_selected
C. element = driver.find_element_by_id('checkbox1')
element_state = element.boolean
D. element = driver.find_element_by_state(id = 'checkbox1')

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 16 of 26
A4Q – Certified Selenium Tester Foundation

Question 25 of 40 | K3 | Number of correct answers: 1 | Maximum achievable credits: 1

Given a dropdown menu with an ID = "dropdown1" and a dropdown option in the


dropdown with a class name = "option3", which line(s) of code will select the dropdown
option?

A. element = driver.find_element_by_class_name('dropdown1.option3')
element.click()
B. dropdown = driver.find_element_by_id('dropdown1')
element = dropdown.find_element_by_class_name('option3')
element.click()
C. dropdown = driver.find_element_by_id(dropdown1)
element = dropdown.find_element_by_class(option3)
element.click
D. dropdown = driver.find_element_by_class_name(option3)
dropdown.click()

Question 26 of 40 | K3 | Number of correct answers: 1 | Maximum achievable credits: 1

Which line(s) of code will allow you to get the text from an alert?

A. alert = driver.switch_to.alert
driver.find_element_by_text('text') in alert
B. alert = driver.switch_to.alert
assert 'alert_text' in alert
C. alert = driver.find_element_by_text('text').alert
D. alert = driver.switch_to.alert
alert_text = alert.text

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 17 of 26
A4Q – Certified Selenium Tester Foundation

Question 27 of 40 | K4 | Number of correct answers: 1 | Maximum achievable credits: 1

For efficiency, you want to create generic functions for locating WebElements.

Which of the following is the BEST approach for such a generic function?

A. Use IDs
B. Use class names
C. Use XPath
D. Use the link text

Question 28 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

Which of the following sentences about logging and reporting in test automation is correct?

A. Logging is used to show the test results (pass/fail), and reporting is used to show the
trace of an automated test execution
B. Logging is used to show errors in an automated test execution only, and reporting is used
to show test data
C. Logging is used to show the trace of an automated test execution, and reporting is used to
show the test results (pass/fail)
D. Logging is not necessary an automated test execution as test scripts contain test steps,
and reporting is used to show the test results (pass/fail)

Question 29 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

Assuming that multiple tabs are open in a Chrome browser whose webdriver object has an
identifier of “driver”, how can the entire browser and all of its tabs be closed at once?

A. driver.close(“ALL”)
B. driver.quit()
C. driver.close()
D. driver.quit(‘ALL’)

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 18 of 26
A4Q – Certified Selenium Tester Foundation

Question 30 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

After working with a specific frame in a web page, which one of the following is the BEST
approach to change the context back to the whole page?

A. Use the switch_to.default_content method


B. Execute JavaScript frame.back code
C. Create a WebDriver object for the page and use the getpage() method
D. Get handles for the open frames and switch to the frame with that handle

Question 31 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

Which method of webdriver object takes screenshot of the whole screen and writes it
to a file?

A. get_screenshot_as_file(<filename>)
B. screenshot(<filename>)
C. get_screenshot_as_file(<filename>, <filetype>)
D. there is no such method, one should use method screenshot and then save it
to a file separately

Question 32 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

What is the main advantage of locating web page elements by their ID?

A. Because the method for finding elements by id has the shortest name
B. Because if a web page is valid XML, this attribute is unique, so element is found
unambiguously
C. Because all HTML tags have that attribute
D. Because this attribute can be used in all location strategies

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 19 of 26
A4Q – Certified Selenium Tester Foundation

Question 33 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

You want to get information on a particular WebElement.


You ensure that the element does exist, and then call the method
ret_value = target_element.get_attribute('text')

Under what conditions might you get the return value None?

Choose the most correct answer.

A. If the WebElement does not have the attribute of 'text'


B. If the WebElement does not have the property 'text'
C. If the WebElement is not currently visible.
D. If the WebElement has neither an attribute nor property 'text'

Question 34 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

In the web application you are testing, you need to type text in a textbox.

Which of the following is the BEST approach for typing text in a textbox using WebDriver?

A. Use the switch_to class to switch to the textbox element, and then typing the text
B. Use the cleartext() method, then use the send_keys(string_to_type)method
to enter the text
C. Click on the textbox and then call textbox("<text to enter">)
D. Use the text(string_to_type) method to enter the text

Question 35 of 40 | K2 | Number of correct answers: 2 | Maximum achievable credits: 1

Which TWO of the following methods close an alert shown by web browser?

A. close()
B. dismiss()
C. escape()
D. accept()
E. quit()

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 20 of 26
A4Q – Certified Selenium Tester Foundation

Question 36 of 40 | K1 | Number of correct answers: 1 | Maximum achievable credits: 1

Which of the following is a good definition for a Page Object Pattern?

A. A test automation approach which requires that technical logic and business logic be dealt
with at different levels
B. A function in a software library whose main purpose is to call another function often
adding or enhancing functionality
C. An application programming interface that treats an HTML or XML document as a tree
structure wherein each node is an object representing a part of the document
D. An API in the SUT which is created predominately to provide enhanced testability

Question 37 of 40 | K2 | Number of correct answers: 1 | Maximum achievable credits: 1

In the web application you are testing, you get the state of several checkboxes.

Which of the following is the BEST approach for making your test scripts maintainable?

A. Assign IDs for each checkbox and each state


B. Create unique tag names for the elements
C. Create a function for getting the state of a checkbox
D. Assign keywords for each checkbox

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 21 of 26
A4Q – Certified Selenium Tester Foundation

Question 38 of 40 | K3 | Number of correct answers: 1 | Maximum achievable credits: 1

In the web application you are testing, a modal dialog should be dismissed when you click on
the cancel button. Given the following code:

from selenium.webdriver.support import expected_conditions as EC


from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
def verify_dialog_dismissed(driver, element_id):
try:
element = wait(driver,5).until\
(EC.[convenience method]((By.ID, element_id)))
except TimeoutException:
element = None
return element

Which of the following wait convenience methods is the MOST appropriate to


replace [convenience method] above to know that the dialog has been dismissed?

A. title_is
B. element_to_be_clickable
C. invisibility_of_element_located
D. presence_of_element_located

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 22 of 26
A4Q – Certified Selenium Tester Foundation

Question 39 of 40 | K4 | Number of correct answers: 1 | Maximum achievable credits: 1

Consider the following HTML excerpt containing a login form:

<form>
User: <input type="edit" id="user" name="user" />
<br/>
Password: <input type="edit" id="password" name="password" />
<br/>
<button type="submit" name="login">Log in</button>&nbsp;
<button type="submit" name="cancel" >Cancel</button>
</form>

Which of the following functions is the best implementation of a method of a Page


Object class for this form:

A. def cancel_login():
drv.find_element_by_id("user").send_keys("admin")
drv.find_element_by_name("cancel").click()
B. def login():
drv.find_element_by_name("cancel").click()
C. def remind_password():
drv.find_element_by_link("remind").click()
D. def cancel_login():
drv.find_element_by_name("cancel").click()

Question 40 of 40 | K4 | Number of correct answers: 1 | Maximum achievable credits: 1

Consider the following test step:

Make a wire transfer from the customer account to the provider account as a
payment for purchased goods.

Which of the following sets of data will be the best parameter set for a keyword implementing this
test step?

A. customer name, provider name, amount to be payed, currency


B. customer account, provider account, payment date
C. customer account, provider account, amount to be payed, currency
D. customer account, customer name, amount to be payed, currency

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 23 of 26
A4Q – Certified Selenium Tester Foundation

Declaration

☒ I hereby confirm that I have answered the questions myself, without the use of prohibited material.
I undertake, such obligation being unlimited in time, to keep confidential the content of the present test
questions and the answer choices, and to refrain from forwarding them to third parties.

Place, Date Signature

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 24 of 26
A4Q – Certified Selenium Tester Foundation

Space for your notes


(notes will neither be read nor evaluated)

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 25 of 26
A4Q – Certified Selenium Tester Foundation

CERTiFYING PEOPLE
43-CSeT-F-Mock isqi.org
Page 26 of 26
1

A4Q
Selenium Tester
Foundation

Answer Sheet - Mock Exam V1.0

Released
Version 2018

Alliance for Qualification

Version 2018
© A4Q Copyright 2018
2

© A4Q Copyright 2018 - Copyright notice

All contents of this work, in particular texts and graphics, are protected by copyright. The use and
exploitation of the work is exclusively the responsibility of the A4Q. In particular, the copying or
duplication of the work but also of parts of this work is prohibited. The A4Q reserves civil and penal
consequences in case of infringement.

Revision History
Version Date Remarks
Version 2018 5 August 2018 1. Release version

Version 2018
© A4Q Copyright 2018
3

Answer Key
Question Number Correct Answer K-Level LO
1 D Keywords 1
2 B Keywords 1
3 A, D STF-1.1 K2
4 A STF-1.2 K2
5 D STF-1.3 K2
6 B STF-1.4 K2
7 C STF-1.5 K2
8 A STF-1.6 K2
9 C STF-1.7 K2
10 C Keywords K1
11 C Keywords K1
12 C STF-2.1 K3
13 B STF-2.2 K3
14 C STF-2.3 K3
15 D STF-2.1 K2
16 A STF-2.2 K2
17 B STF-2.3 K2
18 A Keywords K1
19 B Keywords K1
20 A STF-3.1 K3
21 B, D STF-3.2 K3
22 D STF-3.3 K3
23 B STF-3.4 K3
24 A STF-3.6 K3
25 B STF-3.7 K3
26 D STF-3.8 K3
27 C STF-3.5 K4
28 C STF-3.1 K2
29 B STF-3.2 K2
30 A STF-3.3 K2
31 A STF-3.4 K2
32 B STF-3.5 K2
33 D STF-3.6 K2
34 B STF-3.7 K2
35 B, D STF-3.8 K2
36 A Keywords K1
37 C STF-4.1 K2
38 C STF-4.2 K3
39 D STF-4.3 K4
40 C STF-4.4 K4

Version 2018
© A4Q Copyright 2018
4

Questions with Justifications

Question 1 Keywords K1

What is capture/playback?

A. Incorrect. This is the definition of a wrapper given in the Glossary appendix in STF syllabus
B. Incorrect. This is the syllabus definition for WebDriver
C. Incorrect. This is the ISTQB Glossary for generic test automation architecture
D. Correct. This is the ISTQB Glossary definition

Question 2 Keywords K1

Which of the following is the BEST definition of a test oracle?

A. Incorrect. This does not align with ISTQB Glossary definition of a test oracle
B. Correct. The ISTQB Glossary defines a test oracle as a source to determine expected results
to compare with the actual result of the system under test
C. Incorrect. This does not align with ISTQB Glossary definition of of a test oracle
D. Incorrect. This does not align with ISTQB Glossary definition of of a test oracle

Question 3 STF-1.1 K2

Which two of the following five answers are advantages to using test automation?

A. Correct. As per section 1.1, automation allows us to run tests that manual testers cannot,
for example, some reliability and performance testing
B. Incorrect. As per section 1.1, false positives occur when automation failures are not SUT
failures, but are due to defects in the automation itself
C. Incorrect. As per section 1.1, concentrating on automation can make testers lose sight of
risk management for the project
D. Correct. As per section 1.1, long, boring, brain numbing tests can be automated to keep the
testers from making inattention mistakes
E. Incorrect. While the statement is true, technical debt is not a good thing, as per section 1.1
and the glossary

Version 2018
© A4Q Copyright 2018
5

Question 4 STF-1.2 K2

What is the value of adding additional intelligence via programming to an automated script?

A. Correct. As per section 1.2, by adding extra intelligence to the script, automation can add
more value by more often actually completing the test rather than failing it early
B. Incorrect. As per section 1.1, the added programming can add technical debt, especially if
done poorly
C. Incorrect. As per section 1.2, because an automated script requires more analysis, more
design, more engineering and more maintenance than a manual script, we must figure in the
cost of creating it
D. Incorrect. As per section 1.2, adding intelligence to the script through added programming
can prevent many failures and add value to the testing

Question 5 STF-1.3 K2

Which of the following is NOT an interface level that we could use automation for testing?

A. Incorrect. The GUI level can be used for automation as per section 1.3
B. Incorrect. The service level can be used for SOAP, REST, etc. testing as per section 1.3
C. Incorrect. The protocol level can be used for HTTP, HTTPS, etc. testing as per section 1.3
D. Correct. The abstract level is not an automation level that we can use automation for. As
per section 1.3, this is not a level of interface that automation would use. Instead, we
discuss in section 1.2, and in several other places in the syllabus the advantage of using
abstraction in different ways

Question 6 STF-1.4 K2

Which of the following is a potential benefit that can be obtained by using Selenium WebDriver?

A. Incorrect. Per section 1.4, this is a risk, rather than a potential benefit
B. Correct. Per section 1.4, this is a potential benefit, rather than a risk
C. Incorrect. The pesticide paradox (explained in the ISTQB Foundation syllabus) tells us that
automated tests, when run over and over, tend to find fewer and fewer bugs. As section 1.4
says, “Manual testers are more efficient at finding bugs than is automation”
D. Incorrect. As explained in section 1.6, “automation tends to be quite expensive in both
human effort and tool resources. There is little to no positive return on investment in the
short run; value comes over the long run. Years rather than months.”

Version 2018
© A4Q Copyright 2018
6

Question 7 STF-1.5 K2

Into which part of the test adaptation layer does Selenium fit?

As stated in section 1.5, “Selenium WebDriver fits into the test adaptation layer, providing a
programmatic way to access the SUT through the browser interface.” Since the browser interface is
a graphical user interface, the correct answer is C.

Question 8 STF-1.6 K2

Consider the following metrics that might be useful, given in the syllabus:

Of the metrics, i, ii, and iii are generally useful to measure regression test automation return on
investment. Selenium is used to test application features across various browsers, as explained in
the syllabus, so vi and vii are useful. Selenium is less useful for integration testing and unit testing, so
iv and v are unlikely to be useful.
Therefore, the correct answer is A.

Question 9 STF-1.7 K2

Which of the following Selenium tools can run tests across multiple machines?

As stated in section 1.7 of the syllabus, “Selenium Grid…enables running test scripts across many
machines with many configurations.” Therefore, C is correct.

Question 10 Keywords K1

What is XPath?

A. Incorrect. This is the definition of a CSS selector from the syllabus appendix
B. Incorrect. This is the definition of a python function from the syllabus appendix
C. Correct. This is the definition from the syllabus appendix
D. Incorrect. This is the definition of an iframe from the syllabus appendix

Version 2018
© A4Q Copyright 2018
7

Question 11 Keywords K1

What is a tag in HTML?

A. Incorrect. By definition. See the Glossary appendix in STF syllabus


B. Incorrect. By definition. See the Glossary appendix in STF syllabus
C. Correct. By definition. See the Glossary appendix in STF syllabus
D. Incorrect. By definition. See the Glossary appendix in STF syllabus

Question 12 STF-2.1 K3

Given the following code, which of the options best represents the resulting web page?

A. Incorrect. Per section 2.1, the h1 heading should be more visually important than paragraph
text, and the list should be unordered
B. Incorrect. Per section 2.1, the list should be unordered
C. Correct. Per section 2.1, the h1 heading is more visually important than paragraph text, and
the list is unordered
D. Incorrect. Per section 2.1, the comment should not be displayed and the list should be
unordered

Question 13 STF-2.2 K3

Consider the following XML document:


Which of the following XPath expressions will find the value of UoM attribute for temperature in
New York?

A. Incorrect. This XPath expression gives the text of the node, not an attribute
B. Correct. This XPath finds the UoM attribute of the proper node
C. Incorrect. There is no need to add text() function to the value of a node
D. Incorrect. This is not a valid XPath expression

Version 2018
© A4Q Copyright 2018
8

Question 14 STF-2.3 K3

Consider the following HTML document:


Which HTML element or elements will be found with the following CSS selector?

The correct answer is C. Let’s decompose the selector given in the question:
.first – finds the form with the “first” class
> – finds all children of that form
.big – finds all children of the form, which have the “big” class (there are two of them)
+ – finds an element, which is next to the element from previous line of justification
.button – finds an element with the “button” class; there are two such elements, but only one is
preceded by an element with the “big” class

Question 15 STF-2.1 K2

Which of the following tags opens a new section?

In section 2.1, table 2, the “<div>” tag “defines a section in the document.”
Therefore, the correct answer is D.

Question 16 STF-2.2 K2

Which of the following statements BEST captures the purpose of XPath in Selenium automation?

A. Correct. As explained in section 2.1.1, “Automation with Selenium requires an understanding


of HTML tags. To automate any GUI, the automator must be able to identify each unique
control in the screen being manipulated.” As explained in section 2.2, XPath is a way to
navigate XML documents, with a web page being treated as an XML document.
B. Incorrect. While section 2.2 does describe in detail the creation of XPath expressions, these
expressions are used to locate objects. As explained in section 2.1.1, “Automation with
Selenium requires an understanding of HTML tags. To automate any GUI, the automator
must be able to identify each unique control in the screen being manipulated.”
C. Incorrect. According to section 2.3, this is the purpose of CSS, which “prescribe how the
various HTML elements in a set of HTML documents should render, on the screen, on paper,
or in other media”
D. Incorrect. As stated in section 2.2, “XML always describes a tree format,” while XPath is for
navigating that tree

Version 2018
© A4Q Copyright 2018
9

Question 17 STF-2.3 K2

Which of the following is NOT a way to use CSS in an HTML document?

Section 2.3 lists external style sheets, internal style sheets, and inline styles as the three ways CSS is
used. Outboard style does not exist.
Therefore, the correct answer is B.

Question 18 Keywords K1

What is a wrapper function?

A. Correct. Per the appendix


B. Incorrect. This is an extension of the appendix definition of WebDriver
C. Incorrect. This is an extension of the appendix definition of a framework
D. Incorrect. This is an extension of the appendix definition of DOM

Question 19 Keywords K1

Which of the following is NOT a user prompt?

A. Incorrect. An alert pops up as a modal dialog which forces the user to deal with it before
dealing with the underlying screen as described in section 3.8
B. Correct. An iframe is an HTML inline frame which can hold another HTML document as
defined in the glossary
C. Incorrect. A prompt is similar to an alert in that it pops up as a modal dialog which forces
the user to deal with it before dealing with the underlying screen as described in section 3.8
D. Incorrect. A confirm is similar to an alert in that it pops up as a modal dialog which forces
the user to deal with it before dealing with the underlying screen as described in section 3.8

Question 20 STF-3.1 K3

What will be the output of the execution of following piece of code from the file “question.py”?

A. Correct. This is the proper sequence of the proper lines that will be printed by Python
logging facility
B. Incorrect. The assertion will not throw an exception because test_data equals “Hello world”
C. Incorrect. Wrong sequence of printed lines
D. Incorrect. The assertion will not throw an exception because test_data equals “Hello world”

Version 2018
© A4Q Copyright 2018
10

Question 21 STF-3.2 K3

Given the following piece of code:


What will be the result of its execution (assume that the test environment is configured correctly
and all drivers are present). Choose two:

A. Incorrect. There is no navigation to https://python.org page


B. Correct. There is no navigation on dr1 after getting https://python.org page
C. Incorrect. The get in fifth line will rise an exception and stop execution of the script. The last
line of the script will not be executed
D. Correct. The python_title variable contains the title of https://python.org page, and not its
URL, giving it as the argument to the get method will raise an exception
E. Incorrect. See the justification for right answers

Question 22 STF-3.3 K3

Given a frame with an ID of "frameID", which of the following is/are the best line(s) of code for
changing the context of the test script to back from the frame to the page that the frame is in?

A. Incorrect. Per section 3.3, you need to use the switch_to.default_content()


method, and that is not done in this option
B. Incorrect. Per section 3.3, you need to use the switch_to.default_content()
method, and that is not done in this option
C. Incorrect. Per section 3.3, this is the code for going to the frame
D. Correct. Per section 3.3, this is the correct code

Question 23 STF-3.4 K3

Take into account the following excerpt from a web page:


<a href=”https://python.org” id=”python”><img src=”python.png”
/></a>

Which of the following answers contains the proper Python code for taking a screenshot of the
image python.png? Assume that the variable driver contains the reference to the WebDriver object
for the web browser displaying the page from which the excerpt has been taken.

A. Incorrect. This piece of code does not find the proper HTML element
B. Correct. This piece of code first finds the element enclosing the picture we are interested in,
and then takes a picture of it with screenshot method
C. Incorrect. This piece of code uses wrong method to take a picture
D. Incorrect. This piece of code uses the wrong method to take a picture

Version 2018
© A4Q Copyright 2018
11

Question 24 STF-3.6 K3

Given a checkbox with an ID = "checkbox1", which line(s) of code will get the Boolean value for the
selected state of the checkbox?

A. Correct. Per section 3.6, after you locate the UI element, you can use the is_selected()
method to get the selected state of the element as a boolean value
B. Incorrect. Per section 3.6, you need to locate the UI element first, and that is not done in this
option
C. Incorrect. boolean is not an available Selenium WebDriver method in Python
D. Incorrect. find_element_by_state() is not an available Selenium WebDriver method
in Python

Question 25 STF-3.7 K3

Given a dropdown menu with an ID = "dropdown1" and a dropdown option in the dropdown with a
class name = "option3", which line(s) of code will select the dropdown option?

A. Incorrect. Per section 3.7, you need to locate the dropdown first, and that is not done in this
option
B. Correct. Per section 3.7, after you locate the dropdown, you can use the
find_element_by_class_name method to find the option, and then use the
click() method to click on the option
C. Per section 3.5 and 3.7, find_element_by_class should be
find_element_by_class_name and click should be click(). Also, the ID and
class name should be in quotes
D. Incorrect. Per section 3.7, you need to locate the dropdown first, and that is not done in this
option. Also, the class name should be in quotes

Version 2018
© A4Q Copyright 2018
12

Question 26 STF-3.8 K3

Which line(s) of code will allow you to get the text from an alert?

A. Incorrect. Per section 3.8, you need the text method applied to the alert in the second
line to get the text within the alert; 'in alert' applies to assert statements, not
find_element_by_text
B. Incorrect. Per section 3.8, you need the text method applied to the alert in the second
line to get the text within the alert; this is not done
C. Incorrect. Per section 3.8, you should switch context to the alert first, but you don't. Also,
you need the text method applied to the alert in the second line to get the text within the
alert
D. Correct. Per section 3.8, you need to switch context to the alert first, then get the alert text
via the text method

Question 27 STF-3.5 K4

For efficiency, you want to create generic functions for locating WebElements. Which of the
following is the BEST approach for such a generic function?

A. Incorrect. Per section 3.5, IDs are not appropriate for code which is used in multiple places;
also a tester may not be allowed to modify the SUT to add IDs
B. Incorrect. Per section 3.5, a tester may not be allowed to modify the SUT to add class names
C. Correct. Per section 3.5, you can use XPath in generic locators, using the different "By"
strategies (by id, by class, etc.)
D. Incorrect. There is no indication that there is link text assigned to the WebElements you
need to locate

Question 28 STF-3.1 K2

Which of the following sentences about logging and reporting in test automation is correct?

A. Incorrect. Logging shows details of test execution and reporting shows which test passed
and which failed
B. Incorrect. Logging in test execution usually shows errors of execution, but it also can show
test data and which steps have been executed. Reporting shows which test passed and
which failed.
C. Correct. See STF syllabus section 3.1 for explanation
D. Incorrect. Script sometimes contain decisions and loops, and exact execution sequence
cannot be determined from the code of test scripts only. Logging is necessary. Also log
usually contains concrete test data that have been used during test executions.

Version 2018
© A4Q Copyright 2018
13

Question 29 STF-3.2 K2

Assuming that multiple tabs are open in a Chrome browser whose webdriver object has an identifier
of “driver”, how can the entire browser and all of its tabs be closed at once?

A. Incorrect. driver.close() does not take an argument as defined in section 3.2.3 and our
exercises
B. Correct. This is the correct syntax as defined in section 3.2.3 and our exercises
C. Incorrect. This will close the active window only, not the entire browser as defined in our
exercises and section 3.2.3
D. Incorrect. driver.quit() does not take an argument as defined in our exercises and section
3.2.3

Question 30 STF-3.3 K2

After working with a specific frame in a web page, which one of the following is the BEST approach
to change the context back to the whole page?

A. Correct. Per section 3.3, the switch_to.default_content() method is the best approach
B. Incorrect. There is no JavaScript frame.back
C. Incorrect. There is no method called getpage()
D. Incorrect. Per section 3.3, windows have handles, not frames

Question 31 STF-3.4 K2

Which method of webdriver object takes screenshot of the whole screen and writes it to a file?

A. Correct. Per section 3.4, this method takes a screenshot and saves it to PNG file
B. Incorrect. This is a method of webelement not webdriver
C. Incorrect. Method get_screenshot_as_file takes one argument
D. Incorrect. Method get_screenshot_as_file(<filename>), takes a screenshot
and writes it to a file

Version 2018
© A4Q Copyright 2018
14

Question 32 STF-3.5 K2

What is the main advantage of locating web page elements by their ID.

A. Incorrect. While it is true, this is not a very important trait of this location strategy
B. Correct. See the XML standard
C. Incorrect. This is not true. The HTML and XML tags do not have to have an id attribute to
form valid HTML and XML documents
D. Incorrect. This is not true. It can be used in locating elements by id, CSS selector and XPath,
but not in e.g., partial link or tag name strategy

Question 33 STF-3.6 K2

You want to get information on a particular WebElement. You ensure that the element does exist,
and then call the method
ret_value = target_element.get_attribute('text')

Under what conditions might you get the return value None? Choose the most correct answer.

A. Incorrect. While partially correct, if the WebElement had a property of 'text' it would
return that value as discussed in section 3.6 of the syllabus
B. Incorrect. While partially correct, if the WebElement had an attribute of 'text' it would
return that value as discussed in section 3.6 of the syllabus
C. Incorrect. Visibility has no bearing on the get_attribute() method as discussed in
section 3.6
D. Correct. Only if neither property nor attribute of 'text' existed, the method would return
None as discussed in section 3.6

Question 34 STF-3.7 K2

In the web application you are testing, you need to type text in a textbox. Which of the following is
the BEST approach for typing text in a textbox using WebDriver?

A. Incorrect. Per section 3.8 and the course for 3.3, the switch_to class is used for switching
the context to windows, frames, and alerts, not for locating an element
B. Correct. Per section 3.7, you will want to first clear the element, then type the string desired
C. Incorrect. Per section 3.5, an absolute XPath is discouraged because it can break with the
smallest change to the HTML structure
D. Incorrect. There is no WebDriver text(string_to_type)method

Version 2018
© A4Q Copyright 2018
15

Question 35 STF-3.8 K2

Which two of the following methods close an alert shown by web browser?

A. Incorrect. This method closes active window in web browser


B. Correct. This method dismisses an alert and closes it
C. Incorrect. There is no such method in an alert object
D. Correct. This method accepts an alert and closes it
E. Incorrect. This method closes the web browser

Question 36 Keywords K1

Which of the following is a good definition for a Page Object Pattern?

A. Correct. This is based on the definition from the appendix


B. Incorrect. This is the definition for a wrapper from the appendix
C. Incorrect. This is the definition for Document Object Model (DOM) from the appendix
D. Incorrect. This is the definition for a hook from the appendix

Question 37 STF-4.1 K2

In the web application you are testing, you get the state of several checkboxes. Which of the
following is the BEST approach for making your test scripts maintainable?

A. Incorrect. Per section 3.5, IDs must be unique in the DOM, and since the checkbox could be
in reused code, more information is required to know if this is sound; also, it not possible to
assign an ID to a state
B. Incorrect. In HTML, tags are reserved words that identify elements and they cannot be
interpreted if a programmer creates one
C. Correct. Per section 4.1, code that is used repeatedly should be put in functions
D. Incorrect. Per section 4.4, keywords are business actions or steps in a test case, and they
would not apply in this case

Version 2018
© A4Q Copyright 2018
16

Question 38 STF-4.2 K3

In the web application you are testing, a modal dialog should be dismissed when you click on the
cancel button. Given the following code:

from selenium.webdriver.support import expected_conditions as EC


from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
def verify_dialog_dismissed(driver, element_id):
try:
element = wait(driver,5).until\
(EC.[convenience method]((By.ID, element_id)))
except TimeoutException:
element = None
return element

Which of the following wait convenience methods is the MOST appropriate to replace
[convenience method] above to know that the dialog has been dismissed?

A. Incorrect. title_is does not tell you if an element is visible or invisible, and we want to
know that it is invisible
B. Incorrect. It should be inferred that if an is clickable, it is visible
C. Correct. It should be inferred that when a dialog element is invisible, the dialog has been
dismissed
D. Incorrect. Being present means that an element may be visible or invisible, but we want to
know that it is invisible

Version 2018
© A4Q Copyright 2018
17

Question 39 STF-4.3 K4

Consider the following HTML excerpt containing a login form:

<form>
User: <input type="edit" id="user" name="user" />
<br/>
Password: <input type="edit" id="password" name="password" />
<br/>
<button type="submit" name="login">Log in</button>&nbsp;
<button type="submit" name="cancel" >Cancel</button>
</form>

Which of the following functions is the best implementation of a method of a Page Object class for
this form:

A. Incorrect. This implementation does something else than its name says. Apart from clicking
Cancel button it also writes “admin” in the user edit box.
B. Incorrect. This function clicks Cancel button, but its name says login
C. Incorrect. This form has no link remind
D. Correct. This function clicks the Cancel button. This is one of the business operations, that
can be done using this form.

Question 40 STF-4.4 K4

Consider the following test step:

Make a wire transfer from the customer account to the provider account as a payment for
purchased goods.

Which of the following sets of data will be the best parameter set for a keyword implementing this
test step?

A. Incorrect. Customer name and provider name are not sufficient to make a wire transfer.
Their account numbers are needed.
B. Incorrect. Payment date is not sufficient to make a wire transfer, it actually is not
mandatory. Amount to be payed and currency is needed for every wire transfer.
C. Correct. There are three data items mentioned in this test step: customer data, provider
data and payment data. The latter is decomposed in this answer into amount and currency.
D. Incorrect. There is no provider data in this set

Version 2018
© A4Q Copyright 2018

You might also like