0% found this document useful (0 votes)
84 views28 pages

Testing Web Pages With Selenium: Philip H. Schlesinger

This document provides information about testing web pages using Selenium, an open-source browser automation framework. It discusses why unit testing alone is not sufficient and covers topics like supported browsers, programming languages, testing frameworks, and the Selenium methodology. Instructions are provided on setting up a basic project in IntelliJ using Maven dependencies and encoding actions like hitting enter. Screenshot capturing in code and verifying expected page results are also explained.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views28 pages

Testing Web Pages With Selenium: Philip H. Schlesinger

This document provides information about testing web pages using Selenium, an open-source browser automation framework. It discusses why unit testing alone is not sufficient and covers topics like supported browsers, programming languages, testing frameworks, and the Selenium methodology. Instructions are provided on setting up a basic project in IntelliJ using Maven dependencies and encoding actions like hitting enter. Screenshot capturing in code and verifying expected page results are also explained.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Testing Web Pages With Selenium

Philip H. Schlesinger

Introducing PICS

PICS simplifies the prequalification process.


We help companies to create a safe and sustainable prequalification program for your contractors, vendors and suppliers using a simple, online interface.

PICS PARTIAL MEMBER LIST

PICS Technology Stack

Cobertura

About Me
Since October 2012: Software Development Manager for back-end Java Developers

Whats Selenium

Open-source browser automation framework

Why Not Just Unit Test?

Supported Browsers
12.0.712.0+ 7+

2+

8+

3+

Supported Operating Systems

Supported Programming Languages

Supported Testing Frameworks


(3rd party)

Selenium Methodology

Lets Get Started!

Selenium IDE 101

Using Struts2 Archetype In IntelliJ 12


Simple Form Input Verification

Welcome

Testers

Verify Searching For A Name Returns Some Expected Results


Not As Easy As It Sounds

Welcome BankRate.com Testers

Verify The Loan Calculator Returns Valid Calculations For Several Different Scenarios

Will Require Additional Coding

Another Use For Selenium


Automating Interfaces: Filling In Forms With Same Data Over And Over
Penetration Testing: Filling In Forms With Different Data Over And Over Hitting URLs With Different Data Over And Over

Questions?
Philip H. Schlesinger 1.949.936.4508 [email protected] @PhilSchlesinger http://tipsfromphil.tumblr.com/ http://www.linkedin.com/in/philiphschlesinger

Were Hiring!
Our Blog: http://tech.picsauditing.com/ Currently Open Positions: Java Architect Front-End Architect QA Engineer (SDET)
Apply Directly Here (JobVite Link): http://tinyurl.com/hiremeplz

Addendum How To Replicate The Examples

Setting Up The Basic Struts2 Web Form


In IntelliJ 12: 1. New Project / Maven 2. Create from archetype / org.apache.struts:struts2archetype-starter 3. Correct problems in struts.xml 4. Configure for Tomcat and Run 5. Site will be at http://localhost:8080/index.action

Selenium IDE Firefox Plugin and Server JAR

Download from http://docs.seleniumhq.org/download/

Encoding Hitting The Enter Key In Selenium


Command: keyPressAndWait Target: id=q [depends on your form of course] Value: \\13 [for enter - any ascii value can go here]

Source: http://stackoverflow.com/a/8186216

Capturing A Screenshot In Selenium Code


WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com/"); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); // Now you can do whatever you need to do with it, for example copy somewhere FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

Source: http://stackoverflow.com/a/3423347

Maven Dependency Code


<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.35.0</version> </dependency>

will do the basic job. To start the Selenium server as part of running your tests with Maven:
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-server</artifactId> <version>2.35.0</version> </dependency>

Source: http://docs.seleniumhq.org/download/maven.jsp

For Verifying A Pages Look


At the 2013-10-10 OCJUG presentation, someone asked if Selenium could test if a page actually ended up displaying exactly as expected or if an image was shifted by a pixel or two.

At the time I said I wasnt aware of a way to test a pages look via Selenium, but then I received a tip: 1. Take a snapshot of the correct look of a page via Selenium code 2. Crop at (X,Y) for a certain size A by B
1. This is now your correct snapshot
Take a snapshot of the web page each test Crop at (X,Y) for size A by B Compare the correct snapshot that just-taken-and-cropped snapshot with file size, file hashes, via ImageMagick, or some other methodology

3.

Modify the Selenium code to:


1. 2. 3.

To Learn More About Creating A Selenium Framework For Your Website


Google the following terms: Data Driven Testing (aka DDT)
Involves data mapping and canonical schema mapping between DB and WebObjects, in this sense, it's also a part of Data Integrity Checking effort

Component Modeling Domain Specific Language (or Layer) (aka DSL)


Component Model and DSL is a pure OOD (Object Oriented Design) and that's the core engine to give you an action-command type script interface or just contact me

You might also like