53
Course 12 – 9 January 2017 Adrian Iftene [email protected]

Course 12 9 January 2017 Adrian Iftene [email protected]/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Course 12 ndash 9 January 2017

Adrian Ifteneadifteneinfouaicro

Recapitulation

Code reuse

Ethics

SOLID Principles and Other Principles

Selenium IDE and Selenium WebDriver

2

3

1 Architectures

2 Source Code

3 Data

4 Designs

5 Documentation

6 Templates

7 Human Interfaces

8 Plans

9 Requirements

10 Test Cases

=gt Functionality

SOLID Principles SRP ndash Single Responsibility Principle

OCP ndash OpenClosed Principle

LSP ndash Liskov Substitution Principle

ISP ndash Interface Segregation Principle

DIP ndash Dependency Inversion Principle

DRY ndash Dont Repeat Yourself

YAGNI ndash You Arent Gonna Need It

KISS ndash Keep It Simple Stupid

SOLID was introduced by Robert C Martin in the an article called the ldquoPrinciples of Object Oriented Designrdquo in the early 2000s

Every object should have a single responsibility and all its services should be narrowly aligned with that responsibility

ldquoThe Single Responsibility Principle states that every object should have a single responsibility and that responsibility should be entirely encapsulated by the classrdquo ndash Wikipedia

ldquoThere should never be more than one reason for a class to changerdquo - Robert Martin

Low coupling amp strong cohesion

Classic violations Objects that can printdraw themselves

Objects that can saverestore themselves

Classic solution Separate printer amp Separate saver

Solution Multiple small interfaces (ISP)

Many small classes

Distinct responsibilities

Result Flexible design

Lower coupling amp Higher cohesion

Two responsabilities

Separated interfaces

interface Modem

public void dial(String pno)

public void hangup()

public void send(char c)

public char recv()

interface DataChannel

public void send(char c)

public char recv()

interface Connection

public void dial(String phn)

public char hangup()

Open chest surgery is not needed when putting on a coat

Bertrand Meyer originated the OCP term in his 1988 book Object Oriented Software Construction

ldquoThe Open Closed Principle states that software entities (classes modules functions etc) should be open for extension but closed for modificationrdquo ndashWikipedia

ldquoAll systems change during their life cycles This must be borne in mind when developing systems expected to last longer than the first versionrdquo - Ivar Jacobson

Open to Extension - New behavior can be added in the future

Closed to Modification - Changes to source or binary code are not required

Change behavior without changing code Rely on abstractions not implementations

Do not limit the variety of implementations

In NET ndash Interfaces Abstract Classes

In procedural code - Use parameters

Approaches to achieve OCP Parameters - Pass delegates callbacks

Inheritance Template Method pattern - Child types override behavior of a base class

Composition Strategy pattern - Client code depends on abstraction Plug in model

Classic violations Each change requires re-testing (possible bugs)

Cascading changes through modules

Logic depends on conditional statements

Classic solution New classes (nothing depends on them yet)

New classes (no legacy coupling)

When to apply OCP Experience tell you

OCP add complexity to design (TANSTAAFL)

No design can be closed against all changes

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 2: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Recapitulation

Code reuse

Ethics

SOLID Principles and Other Principles

Selenium IDE and Selenium WebDriver

2

3

1 Architectures

2 Source Code

3 Data

4 Designs

5 Documentation

6 Templates

7 Human Interfaces

8 Plans

9 Requirements

10 Test Cases

=gt Functionality

SOLID Principles SRP ndash Single Responsibility Principle

OCP ndash OpenClosed Principle

LSP ndash Liskov Substitution Principle

ISP ndash Interface Segregation Principle

DIP ndash Dependency Inversion Principle

DRY ndash Dont Repeat Yourself

YAGNI ndash You Arent Gonna Need It

KISS ndash Keep It Simple Stupid

SOLID was introduced by Robert C Martin in the an article called the ldquoPrinciples of Object Oriented Designrdquo in the early 2000s

Every object should have a single responsibility and all its services should be narrowly aligned with that responsibility

ldquoThe Single Responsibility Principle states that every object should have a single responsibility and that responsibility should be entirely encapsulated by the classrdquo ndash Wikipedia

ldquoThere should never be more than one reason for a class to changerdquo - Robert Martin

Low coupling amp strong cohesion

Classic violations Objects that can printdraw themselves

Objects that can saverestore themselves

Classic solution Separate printer amp Separate saver

Solution Multiple small interfaces (ISP)

Many small classes

Distinct responsibilities

Result Flexible design

Lower coupling amp Higher cohesion

Two responsabilities

Separated interfaces

interface Modem

public void dial(String pno)

public void hangup()

public void send(char c)

public char recv()

interface DataChannel

public void send(char c)

public char recv()

interface Connection

public void dial(String phn)

public char hangup()

Open chest surgery is not needed when putting on a coat

Bertrand Meyer originated the OCP term in his 1988 book Object Oriented Software Construction

ldquoThe Open Closed Principle states that software entities (classes modules functions etc) should be open for extension but closed for modificationrdquo ndashWikipedia

ldquoAll systems change during their life cycles This must be borne in mind when developing systems expected to last longer than the first versionrdquo - Ivar Jacobson

Open to Extension - New behavior can be added in the future

Closed to Modification - Changes to source or binary code are not required

Change behavior without changing code Rely on abstractions not implementations

Do not limit the variety of implementations

In NET ndash Interfaces Abstract Classes

In procedural code - Use parameters

Approaches to achieve OCP Parameters - Pass delegates callbacks

Inheritance Template Method pattern - Child types override behavior of a base class

Composition Strategy pattern - Client code depends on abstraction Plug in model

Classic violations Each change requires re-testing (possible bugs)

Cascading changes through modules

Logic depends on conditional statements

Classic solution New classes (nothing depends on them yet)

New classes (no legacy coupling)

When to apply OCP Experience tell you

OCP add complexity to design (TANSTAAFL)

No design can be closed against all changes

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 3: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

3

1 Architectures

2 Source Code

3 Data

4 Designs

5 Documentation

6 Templates

7 Human Interfaces

8 Plans

9 Requirements

10 Test Cases

=gt Functionality

SOLID Principles SRP ndash Single Responsibility Principle

OCP ndash OpenClosed Principle

LSP ndash Liskov Substitution Principle

ISP ndash Interface Segregation Principle

DIP ndash Dependency Inversion Principle

DRY ndash Dont Repeat Yourself

YAGNI ndash You Arent Gonna Need It

KISS ndash Keep It Simple Stupid

SOLID was introduced by Robert C Martin in the an article called the ldquoPrinciples of Object Oriented Designrdquo in the early 2000s

Every object should have a single responsibility and all its services should be narrowly aligned with that responsibility

ldquoThe Single Responsibility Principle states that every object should have a single responsibility and that responsibility should be entirely encapsulated by the classrdquo ndash Wikipedia

ldquoThere should never be more than one reason for a class to changerdquo - Robert Martin

Low coupling amp strong cohesion

Classic violations Objects that can printdraw themselves

Objects that can saverestore themselves

Classic solution Separate printer amp Separate saver

Solution Multiple small interfaces (ISP)

Many small classes

Distinct responsibilities

Result Flexible design

Lower coupling amp Higher cohesion

Two responsabilities

Separated interfaces

interface Modem

public void dial(String pno)

public void hangup()

public void send(char c)

public char recv()

interface DataChannel

public void send(char c)

public char recv()

interface Connection

public void dial(String phn)

public char hangup()

Open chest surgery is not needed when putting on a coat

Bertrand Meyer originated the OCP term in his 1988 book Object Oriented Software Construction

ldquoThe Open Closed Principle states that software entities (classes modules functions etc) should be open for extension but closed for modificationrdquo ndashWikipedia

ldquoAll systems change during their life cycles This must be borne in mind when developing systems expected to last longer than the first versionrdquo - Ivar Jacobson

Open to Extension - New behavior can be added in the future

Closed to Modification - Changes to source or binary code are not required

Change behavior without changing code Rely on abstractions not implementations

Do not limit the variety of implementations

In NET ndash Interfaces Abstract Classes

In procedural code - Use parameters

Approaches to achieve OCP Parameters - Pass delegates callbacks

Inheritance Template Method pattern - Child types override behavior of a base class

Composition Strategy pattern - Client code depends on abstraction Plug in model

Classic violations Each change requires re-testing (possible bugs)

Cascading changes through modules

Logic depends on conditional statements

Classic solution New classes (nothing depends on them yet)

New classes (no legacy coupling)

When to apply OCP Experience tell you

OCP add complexity to design (TANSTAAFL)

No design can be closed against all changes

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 4: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

SOLID Principles SRP ndash Single Responsibility Principle

OCP ndash OpenClosed Principle

LSP ndash Liskov Substitution Principle

ISP ndash Interface Segregation Principle

DIP ndash Dependency Inversion Principle

DRY ndash Dont Repeat Yourself

YAGNI ndash You Arent Gonna Need It

KISS ndash Keep It Simple Stupid

SOLID was introduced by Robert C Martin in the an article called the ldquoPrinciples of Object Oriented Designrdquo in the early 2000s

Every object should have a single responsibility and all its services should be narrowly aligned with that responsibility

ldquoThe Single Responsibility Principle states that every object should have a single responsibility and that responsibility should be entirely encapsulated by the classrdquo ndash Wikipedia

ldquoThere should never be more than one reason for a class to changerdquo - Robert Martin

Low coupling amp strong cohesion

Classic violations Objects that can printdraw themselves

Objects that can saverestore themselves

Classic solution Separate printer amp Separate saver

Solution Multiple small interfaces (ISP)

Many small classes

Distinct responsibilities

Result Flexible design

Lower coupling amp Higher cohesion

Two responsabilities

Separated interfaces

interface Modem

public void dial(String pno)

public void hangup()

public void send(char c)

public char recv()

interface DataChannel

public void send(char c)

public char recv()

interface Connection

public void dial(String phn)

public char hangup()

Open chest surgery is not needed when putting on a coat

Bertrand Meyer originated the OCP term in his 1988 book Object Oriented Software Construction

ldquoThe Open Closed Principle states that software entities (classes modules functions etc) should be open for extension but closed for modificationrdquo ndashWikipedia

ldquoAll systems change during their life cycles This must be borne in mind when developing systems expected to last longer than the first versionrdquo - Ivar Jacobson

Open to Extension - New behavior can be added in the future

Closed to Modification - Changes to source or binary code are not required

Change behavior without changing code Rely on abstractions not implementations

Do not limit the variety of implementations

In NET ndash Interfaces Abstract Classes

In procedural code - Use parameters

Approaches to achieve OCP Parameters - Pass delegates callbacks

Inheritance Template Method pattern - Child types override behavior of a base class

Composition Strategy pattern - Client code depends on abstraction Plug in model

Classic violations Each change requires re-testing (possible bugs)

Cascading changes through modules

Logic depends on conditional statements

Classic solution New classes (nothing depends on them yet)

New classes (no legacy coupling)

When to apply OCP Experience tell you

OCP add complexity to design (TANSTAAFL)

No design can be closed against all changes

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 5: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

SOLID was introduced by Robert C Martin in the an article called the ldquoPrinciples of Object Oriented Designrdquo in the early 2000s

Every object should have a single responsibility and all its services should be narrowly aligned with that responsibility

ldquoThe Single Responsibility Principle states that every object should have a single responsibility and that responsibility should be entirely encapsulated by the classrdquo ndash Wikipedia

ldquoThere should never be more than one reason for a class to changerdquo - Robert Martin

Low coupling amp strong cohesion

Classic violations Objects that can printdraw themselves

Objects that can saverestore themselves

Classic solution Separate printer amp Separate saver

Solution Multiple small interfaces (ISP)

Many small classes

Distinct responsibilities

Result Flexible design

Lower coupling amp Higher cohesion

Two responsabilities

Separated interfaces

interface Modem

public void dial(String pno)

public void hangup()

public void send(char c)

public char recv()

interface DataChannel

public void send(char c)

public char recv()

interface Connection

public void dial(String phn)

public char hangup()

Open chest surgery is not needed when putting on a coat

Bertrand Meyer originated the OCP term in his 1988 book Object Oriented Software Construction

ldquoThe Open Closed Principle states that software entities (classes modules functions etc) should be open for extension but closed for modificationrdquo ndashWikipedia

ldquoAll systems change during their life cycles This must be borne in mind when developing systems expected to last longer than the first versionrdquo - Ivar Jacobson

Open to Extension - New behavior can be added in the future

Closed to Modification - Changes to source or binary code are not required

Change behavior without changing code Rely on abstractions not implementations

Do not limit the variety of implementations

In NET ndash Interfaces Abstract Classes

In procedural code - Use parameters

Approaches to achieve OCP Parameters - Pass delegates callbacks

Inheritance Template Method pattern - Child types override behavior of a base class

Composition Strategy pattern - Client code depends on abstraction Plug in model

Classic violations Each change requires re-testing (possible bugs)

Cascading changes through modules

Logic depends on conditional statements

Classic solution New classes (nothing depends on them yet)

New classes (no legacy coupling)

When to apply OCP Experience tell you

OCP add complexity to design (TANSTAAFL)

No design can be closed against all changes

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 6: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Every object should have a single responsibility and all its services should be narrowly aligned with that responsibility

ldquoThe Single Responsibility Principle states that every object should have a single responsibility and that responsibility should be entirely encapsulated by the classrdquo ndash Wikipedia

ldquoThere should never be more than one reason for a class to changerdquo - Robert Martin

Low coupling amp strong cohesion

Classic violations Objects that can printdraw themselves

Objects that can saverestore themselves

Classic solution Separate printer amp Separate saver

Solution Multiple small interfaces (ISP)

Many small classes

Distinct responsibilities

Result Flexible design

Lower coupling amp Higher cohesion

Two responsabilities

Separated interfaces

interface Modem

public void dial(String pno)

public void hangup()

public void send(char c)

public char recv()

interface DataChannel

public void send(char c)

public char recv()

interface Connection

public void dial(String phn)

public char hangup()

Open chest surgery is not needed when putting on a coat

Bertrand Meyer originated the OCP term in his 1988 book Object Oriented Software Construction

ldquoThe Open Closed Principle states that software entities (classes modules functions etc) should be open for extension but closed for modificationrdquo ndashWikipedia

ldquoAll systems change during their life cycles This must be borne in mind when developing systems expected to last longer than the first versionrdquo - Ivar Jacobson

Open to Extension - New behavior can be added in the future

Closed to Modification - Changes to source or binary code are not required

Change behavior without changing code Rely on abstractions not implementations

Do not limit the variety of implementations

In NET ndash Interfaces Abstract Classes

In procedural code - Use parameters

Approaches to achieve OCP Parameters - Pass delegates callbacks

Inheritance Template Method pattern - Child types override behavior of a base class

Composition Strategy pattern - Client code depends on abstraction Plug in model

Classic violations Each change requires re-testing (possible bugs)

Cascading changes through modules

Logic depends on conditional statements

Classic solution New classes (nothing depends on them yet)

New classes (no legacy coupling)

When to apply OCP Experience tell you

OCP add complexity to design (TANSTAAFL)

No design can be closed against all changes

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 7: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

ldquoThe Single Responsibility Principle states that every object should have a single responsibility and that responsibility should be entirely encapsulated by the classrdquo ndash Wikipedia

ldquoThere should never be more than one reason for a class to changerdquo - Robert Martin

Low coupling amp strong cohesion

Classic violations Objects that can printdraw themselves

Objects that can saverestore themselves

Classic solution Separate printer amp Separate saver

Solution Multiple small interfaces (ISP)

Many small classes

Distinct responsibilities

Result Flexible design

Lower coupling amp Higher cohesion

Two responsabilities

Separated interfaces

interface Modem

public void dial(String pno)

public void hangup()

public void send(char c)

public char recv()

interface DataChannel

public void send(char c)

public char recv()

interface Connection

public void dial(String phn)

public char hangup()

Open chest surgery is not needed when putting on a coat

Bertrand Meyer originated the OCP term in his 1988 book Object Oriented Software Construction

ldquoThe Open Closed Principle states that software entities (classes modules functions etc) should be open for extension but closed for modificationrdquo ndashWikipedia

ldquoAll systems change during their life cycles This must be borne in mind when developing systems expected to last longer than the first versionrdquo - Ivar Jacobson

Open to Extension - New behavior can be added in the future

Closed to Modification - Changes to source or binary code are not required

Change behavior without changing code Rely on abstractions not implementations

Do not limit the variety of implementations

In NET ndash Interfaces Abstract Classes

In procedural code - Use parameters

Approaches to achieve OCP Parameters - Pass delegates callbacks

Inheritance Template Method pattern - Child types override behavior of a base class

Composition Strategy pattern - Client code depends on abstraction Plug in model

Classic violations Each change requires re-testing (possible bugs)

Cascading changes through modules

Logic depends on conditional statements

Classic solution New classes (nothing depends on them yet)

New classes (no legacy coupling)

When to apply OCP Experience tell you

OCP add complexity to design (TANSTAAFL)

No design can be closed against all changes

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 8: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Classic violations Objects that can printdraw themselves

Objects that can saverestore themselves

Classic solution Separate printer amp Separate saver

Solution Multiple small interfaces (ISP)

Many small classes

Distinct responsibilities

Result Flexible design

Lower coupling amp Higher cohesion

Two responsabilities

Separated interfaces

interface Modem

public void dial(String pno)

public void hangup()

public void send(char c)

public char recv()

interface DataChannel

public void send(char c)

public char recv()

interface Connection

public void dial(String phn)

public char hangup()

Open chest surgery is not needed when putting on a coat

Bertrand Meyer originated the OCP term in his 1988 book Object Oriented Software Construction

ldquoThe Open Closed Principle states that software entities (classes modules functions etc) should be open for extension but closed for modificationrdquo ndashWikipedia

ldquoAll systems change during their life cycles This must be borne in mind when developing systems expected to last longer than the first versionrdquo - Ivar Jacobson

Open to Extension - New behavior can be added in the future

Closed to Modification - Changes to source or binary code are not required

Change behavior without changing code Rely on abstractions not implementations

Do not limit the variety of implementations

In NET ndash Interfaces Abstract Classes

In procedural code - Use parameters

Approaches to achieve OCP Parameters - Pass delegates callbacks

Inheritance Template Method pattern - Child types override behavior of a base class

Composition Strategy pattern - Client code depends on abstraction Plug in model

Classic violations Each change requires re-testing (possible bugs)

Cascading changes through modules

Logic depends on conditional statements

Classic solution New classes (nothing depends on them yet)

New classes (no legacy coupling)

When to apply OCP Experience tell you

OCP add complexity to design (TANSTAAFL)

No design can be closed against all changes

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 9: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Two responsabilities

Separated interfaces

interface Modem

public void dial(String pno)

public void hangup()

public void send(char c)

public char recv()

interface DataChannel

public void send(char c)

public char recv()

interface Connection

public void dial(String phn)

public char hangup()

Open chest surgery is not needed when putting on a coat

Bertrand Meyer originated the OCP term in his 1988 book Object Oriented Software Construction

ldquoThe Open Closed Principle states that software entities (classes modules functions etc) should be open for extension but closed for modificationrdquo ndashWikipedia

ldquoAll systems change during their life cycles This must be borne in mind when developing systems expected to last longer than the first versionrdquo - Ivar Jacobson

Open to Extension - New behavior can be added in the future

Closed to Modification - Changes to source or binary code are not required

Change behavior without changing code Rely on abstractions not implementations

Do not limit the variety of implementations

In NET ndash Interfaces Abstract Classes

In procedural code - Use parameters

Approaches to achieve OCP Parameters - Pass delegates callbacks

Inheritance Template Method pattern - Child types override behavior of a base class

Composition Strategy pattern - Client code depends on abstraction Plug in model

Classic violations Each change requires re-testing (possible bugs)

Cascading changes through modules

Logic depends on conditional statements

Classic solution New classes (nothing depends on them yet)

New classes (no legacy coupling)

When to apply OCP Experience tell you

OCP add complexity to design (TANSTAAFL)

No design can be closed against all changes

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 10: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Open chest surgery is not needed when putting on a coat

Bertrand Meyer originated the OCP term in his 1988 book Object Oriented Software Construction

ldquoThe Open Closed Principle states that software entities (classes modules functions etc) should be open for extension but closed for modificationrdquo ndashWikipedia

ldquoAll systems change during their life cycles This must be borne in mind when developing systems expected to last longer than the first versionrdquo - Ivar Jacobson

Open to Extension - New behavior can be added in the future

Closed to Modification - Changes to source or binary code are not required

Change behavior without changing code Rely on abstractions not implementations

Do not limit the variety of implementations

In NET ndash Interfaces Abstract Classes

In procedural code - Use parameters

Approaches to achieve OCP Parameters - Pass delegates callbacks

Inheritance Template Method pattern - Child types override behavior of a base class

Composition Strategy pattern - Client code depends on abstraction Plug in model

Classic violations Each change requires re-testing (possible bugs)

Cascading changes through modules

Logic depends on conditional statements

Classic solution New classes (nothing depends on them yet)

New classes (no legacy coupling)

When to apply OCP Experience tell you

OCP add complexity to design (TANSTAAFL)

No design can be closed against all changes

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 11: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

ldquoThe Open Closed Principle states that software entities (classes modules functions etc) should be open for extension but closed for modificationrdquo ndashWikipedia

ldquoAll systems change during their life cycles This must be borne in mind when developing systems expected to last longer than the first versionrdquo - Ivar Jacobson

Open to Extension - New behavior can be added in the future

Closed to Modification - Changes to source or binary code are not required

Change behavior without changing code Rely on abstractions not implementations

Do not limit the variety of implementations

In NET ndash Interfaces Abstract Classes

In procedural code - Use parameters

Approaches to achieve OCP Parameters - Pass delegates callbacks

Inheritance Template Method pattern - Child types override behavior of a base class

Composition Strategy pattern - Client code depends on abstraction Plug in model

Classic violations Each change requires re-testing (possible bugs)

Cascading changes through modules

Logic depends on conditional statements

Classic solution New classes (nothing depends on them yet)

New classes (no legacy coupling)

When to apply OCP Experience tell you

OCP add complexity to design (TANSTAAFL)

No design can be closed against all changes

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 12: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Change behavior without changing code Rely on abstractions not implementations

Do not limit the variety of implementations

In NET ndash Interfaces Abstract Classes

In procedural code - Use parameters

Approaches to achieve OCP Parameters - Pass delegates callbacks

Inheritance Template Method pattern - Child types override behavior of a base class

Composition Strategy pattern - Client code depends on abstraction Plug in model

Classic violations Each change requires re-testing (possible bugs)

Cascading changes through modules

Logic depends on conditional statements

Classic solution New classes (nothing depends on them yet)

New classes (no legacy coupling)

When to apply OCP Experience tell you

OCP add complexity to design (TANSTAAFL)

No design can be closed against all changes

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 13: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Classic violations Each change requires re-testing (possible bugs)

Cascading changes through modules

Logic depends on conditional statements

Classic solution New classes (nothing depends on them yet)

New classes (no legacy coupling)

When to apply OCP Experience tell you

OCP add complexity to design (TANSTAAFL)

No design can be closed against all changes

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 14: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Open-Close Principle - Bad example

class GraphicEditor

public void drawShape(Shape s)

if (sm_type==1)

drawRectangle(s)

else if (sm_type==2)

drawCircle(s)

public void drawCircle(Circle r)

public void drawRectangle(Rectangle r)

class Shape

int m_type

class Rectangle extends Shape

Rectangle() superm_type=1

class Circle extends Shape

Circle() superm_type=2

Open-Close Principle - Good

example

class GraphicEditor

public void drawShape(Shape s)

sdraw()

class Shape

abstract void draw()

class Rectangle extends Shape

public void draw()

draw the rectangle

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 15: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

If it looks like a duck quacks like a duck but needs batteries ndash you probably have the wrong abstraction

Barbara Liskov described the principle in 1988

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 16: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

The Liskov Substitution Principle states that Subtypes must be substitutable for their base typesldquo - Agile Principles Patterns and Practices in C

Substitutability ndash child classes must not Remove base class behavior

Violate base class invariants

Normal OOP inheritance IS-A relationship

Liskov Substitution inheritance IS-SUBSTITUTABLE-FOR

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 17: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

The problem Polymorphism break

Client code expectations

Fixing by adding if-then ndash nightmare (OCP)

Classic violations Type checking for different methods

Not implemented overridden methods

Virtual methods in constructor

Solutions ldquoTell Donrsquot Askrdquo - Donrsquot ask for types and Tell the

object what to do

Refactoring to base class- Common functionality and Introduce third class

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 18: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Violation of Liskovs Substitution Principle

class Rectangle

int m_width

int m_height

public void setWidth(int width)

m_width = width

public void setHeight(int h)

m_height = ht

public int getWidth()

return m_width

public int getHeight()

return m_height

public int getArea()

return m_width m_height

class Square extends Rectangle

public void setWidth(int width)

m_width = width

m_height = width

public void setHeight(int height)

m_width = height

m_height = height

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 19: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

class LspTestprivate static Rectangle getNewRectangle()

it can be an object returned by some factory return new Square()

public static void main (String args[])

Rectangle r = LspTestgetNewRectangle()rsetWidth(5)rsetHeight(10)

user knows that r its a rectangle It assumes that hes able to set the width and height as for the base class

Systemoutprintln(rgetArea()) now hes surprised to see that the area is 100 instead of 50

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 20: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

You want me to plug this in Where

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 21: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

ldquoThe Interface Segregation Principle states that Clients should not be forced to depend on methods they do not userdquo - Agile Principles Patterns and Practices in C

Prefer small cohesive interfaces - Interface is the interface type + All public members of a class

Divide fat interfaces into smaller ones ldquofatrdquo interfaces means classes with useless methods

increased coupling reduced flexibility and maintainability

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 22: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Classic violations Unimplemented methods (also in LSP)

Use of only small portion of a class

When to fix Once there is pain Do not fix if is not broken

If the fat interface is yours separate it to smaller ones

If the fat interface is not yours use Adapter pattern

Solutions Small interfaces

Cohesive interfaces

Focused interfaces

Let the client define interfaces

Package interfaces with their implementation

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 23: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Bad example (polluted interface)

interface Worker

void work()

void eat()

ManWorker implements Worker

void work() hellip

void eat() 30 min break

RobotWorker implements Worker

void work() hellip

void eat() Not Appliciable

for a RobotWorker

Solution split into two interfaces

interface Workable

public void work()

interface Feedable

public void eat()

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 24: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Would you solder a lamp directly to the electrical wiring in a wall

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 25: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

ldquoHigh-level modules should not depend on low-level modules Both should depend on abstractionsrdquo

ldquoAbstractions should not depend on details Details should depend on abstractionsrdquo -Agile Principles Patterns and Practices in C

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 26: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Framework

Third Party Libraries

Database

File System

Email

Web Services

System Resources (Clock)

Configuration

The new Keyword

Static methods

ThreadSleep

Random

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 27: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

How it should be Classes should declare what they need

Constructors should require dependencies

Dependencies should be abstractions and be shown

How to do it Dependency Injection

The Hollywood principle Dont call us well call you

Classic violations Using of the new keyword static methodsproperties

How to fix Default constructor main methodstarting point

Inversion of Control container

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 28: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

DIP - bad example

public class EmployeeService

private EmployeeFinder emFinder concrete class not abstract Can access a SQL DB for instance

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

DIP - fixed

public class EmployeeService

private IEmployeeFinder emFinder depends on an abstraction no an implementation

public Employee findEmployee(hellip)

emFinderfindEmployee(hellip)

Now its possible to change the finder to be a XmlEmployeeFinder DBEmployeeFinder FlatFileEmployeeFinder

MockEmployeeFinderhellip

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 29: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Dont Repeat Yourself (DRY)

You Aint Gonna Need It (YAGNI)

Keep It Simple Stupid (KISS)

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 30: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Repetition is the root of all software evil

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 31: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Every piece of knowledge must have a single unambiguous representation in the systemldquo - The Pragmatic Programmer

Repetition in logic calls for abstraction Repetition in process calls for automationldquo -97 Things Every Programmer Should Know

Variations include Once and Only Once

Duplication Is Evil (DIE)

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 32: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Magic StringsValues

Duplicate logic in multiple locations

Repeated if-then logic

Conditionals instead of polymorphism

Repeated Execution Patterns

Lots of duplicate probably copy-pasted code

Only manual tests

Static methods everywhere

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 33: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Donrsquot waste resources on what you might need

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 34: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

A programmer should not add functionality until deemed necessaryldquo ndash Wikipedia

Always implement things when you actually need them never when you just foresee that you need themldquo - Ron Jeffries XP co-founder

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 35: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Time for adding testing improving

Debugging documented supported

Difficult for requirements

Larger and complicate software

May lead to adding even more features

May be not know to clients

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 36: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

You donrsquot need to know the entire universe when living on the Earth

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 37: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Most systems work best if they are kept simpleldquo - US Navy

Simplicity should be a key goal in design and unnecessary complexity should be avoidedldquo - Wikipedia

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 38: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

A tool set automates web app testing across platforms

Can simulate user interactions in browser

Two components Selenium IDE

Selenium WebDriver (aka Selenium 2)

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 39: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

httpwwwseleniumhqorgprojectside

httpwwwseleniumhqorgdownload

httpsaddonsmozillaorgen-USfirefoxaddonselenium-ide

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 40: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Firefox extension

Easy record and replay

Debug and set breakpoints

Save tests in HTML WebDriver and other formats

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 41: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

1 Start recording in Selenium IDE

2 Execute scenario on running web application

3 Stop recording in Selenium IDE

4 Verify Add assertions

5 Replay the test

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 42: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Selenium saves all information in an HTML table format

Each record consists of Command ndash tells Selenium what to do (eg ldquoopenrdquo

ldquotyperdquo ldquoclickrdquo ldquoverifyTextrdquo)

Target ndash tells Selenium which HTML element a command refers to (eg textbox header table)

Value ndash used for any command that might need a value of some kind (eg type something into a textbox)

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 43: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

type(locator value)

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 44: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

No multiple browsers support It runs only in Mozilla Firefox

No manual scripts Eg conditions and Loops for Data Driven Testing

Fancy test cases -gt Selenium WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 45: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

Selenium-WebDriver A piece of program

Control the browser by programming

More flexible and powerful

Selenium-WebDriver supports multiple browsers in multiple platforms Google Chrome 1207120+

Internet Explorer 6+

Firefox 30+

Opera 115+

Android ndash 23+ for phones and tablets

iOS 3+ for phones

iOS 32+ for tablets

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 46: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver script runs for different platforms

Support multiple programming language Java C Python Ruby PHP Perlhellip

Itrsquos efficient WebDriver leverages each browserrsquos native support

for automation

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 47: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

The easiest way is use Maven Maven will download the java bindings (the Selenium 20 java client library) and all its dependencies and will create the project for you using a maven pomxml (project configuration) file

You can then import the maven project into your preferred IDE IntelliJ IDEA or Eclipse

From a command-line CD into the project directory and run maven as follows mvn clean install

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 48: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

A solution for the automated testing Simulate user actions

Functional testing

Create regression tests to verify functionality and user acceptance

Browser compatibility testing

The same script can run on any Selenium platform

Load testing

Stress testing

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 49: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

public static void main( String[] args )

Create a new instance of the Firefox driver

WebDriver driver = new FirefoxDriver()

(1) Go to a page

driverget(httpwwwgooglecom)

(2) Locate an element

WebElement element = driverfindElement(Byname(q))

(3-1) Enter something to search for

elementsendKeys(Purdue Univeristy)

(3-2) Now submit the form WebDriver will find the form for us from the element

elementsubmit()

(3-3) Wait up to 10 seconds for a condition

WebDriverWait waiting = new WebDriverWait(driver 10)

waitinguntil( ExpectedConditionspresenceOfElementLocated( Byid(pnnext) ) )

(4) Check the title of the page

if( drivergetTitle()equals(purdue univeristy -Google Search) )

Systemoutprintln(PASS)

else

Systemerrprintln(FAIL)

Close the browser

driverquit()

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 50: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

51

httpsgithubcomflextryTelerik-AcademyblobmasterProgramming20with20C23420C2320High-Quality20Code1620SOLID20and20Other20PrinciplesSOLID20and20Other20Principlespptx

httpwwwslidesharenetneetuangelmishrappt-12735983

httpwwwslidesharenetSamHennessyimplementing-the-openclosed-principle

httpfilesmeetupcom1413801Magenic20Speaker20Architecture20Solid20V4-spptx

httpwwwslidesharenetenbohmsolid-design-principles-9016117

httpblogadnanmasoodcomwp-contentuploads201212SOLID-Presentation-Inland-Empire-UG1pptx

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 51: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

52

httpspeoplecspittedu~chang231y14seleniumpptx

httpswwwcspurdueeduhomesxyzhangfall12seleniumppt

httpswwwtutorialspointcomseleniumselenium_tutorialpdf

httpscholarharvardedufilestcheng2filesselenium_documentation_0pdf

httpossinfosciencecojpseleniumhqdocsbookSelenium_Documentationpdf

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988

Page 52: Course 12 9 January 2017 Adrian Iftene adiftene@info.uaicadiftene/Scoala/2017/... · WebDriver is designed to providing a simpler and uniformed programming interface Same WebDriver

53

Principles of Object Oriented Design Robert C Martin 2000 httpwwwobjectmentorcomomTeammartin_rhtml

Object Oriented Software Construction Bertrand Meyer 1988