Automated Web Testing

3m ago
2 Views
1 Downloads
506.68 KB
10 Pages
Last View : 3m ago
Last Download : 3m ago
Upload by : Asher Boatman
Transcription

Automated Web Testing with Selenium Erik Doernenburg ThoughtWorks Agenda What is Selenium? Writing Maintainable Tests

What is Selenium? Test tool for web applications Runs in any mainstream browser Supports tests in many languages Selenese (pure HTML, no backend required) Java, C#, Perl, Python, Ruby Record/playback (Selenium IDE) Open Source with corporate backing Lives at selenium.openqa.org Demo Record a test in Selenium IDE Show same test written in Java

Java Test example public void testGoogleTestSearch() throws Exception { selenium.open("http://www.google.com/webhp"); assertEquals("Google", selenium.getTitle()); selenium.type("q", "Selenium OpenQA"); selenium.click("btnG"); selenium.waitForPageToLoad("5000"); assertEquals("Selenium OpenQA - Google Search", selenium.getTitle()); } Java SetUp/TearDown example public void setUp() throws Exception { selenium new DefaultSelenium( "localhost", 4444, "*chrome", "http://www.google.com"); selenium.start(); } public void tearDown() throws Exception { selenium.stop(); }

A few Selenese commands click getHtmlSource isVisible close getTitle keyPress createCookie getValue mouseOver dragdrop goBack open fireEvent isElementPresent refresh getEval isTextPresent type Element locators selenium.click("btnG"); ID: id foo Name: name foo First ID, then name: identifier foo DOM: document.forms[‘myform’].myDropdown XPath: xpath //table[@id 'table1']//tr[4]/td[2] Link Text: link sometext CSS Selector: css a[href “#id3”] Sensible defaults, e.g. xpath if starts with //

How Selenium works Agenda What is Selenium? Writing Maintainable Tests

Standard end-user black-box test 1. Login as administrator 2. Create a user 3. Log out 4. Login as that user 5. Create a folder 6. Create a thingy in that folder 7. Search for that thingy in the search box 8. Make sure your thingy shows up on the search results page Fragile Automated Tests Exercising irrelevant features Logging in/Logging out Creating a folder Creating a thingy If the UI for any one of those features changes, your search test fails

Know when to record tests Recorded tests reuse no code “Record & Tweak” vs. “Fire and Forget” Slight change in folder creator page means all of those tests have to be re-recorded from scratch Use the recorder to create reusable code Unit testing vs. Integration testing Selenium tests are integration tests Functional/Acceptance/User/Compatibility Unit tests verify a unit in isolation If FooTest.java fails, the bug must be in Foo.java Cannot fail due to browser incompatibilities Must be completely isolated from each other Integration tests verify that units work together Requires testing multiple configurations (browsers) Tend to build on the side-effects of earlier tests

Presentation Model Create a layer of classes that mimic the UI a field for every text box, etc. a method for every button Test the application flow using this model Can use normal unit test framework Insulated from design changes Use Selenium to check wiring and browser compatibility Create abstractions Tests can use all language features extract method, inheritance, public void testSearchForThingy() { createTestUserAndLogin(); createThingyInFolder("Foo", "Test Folder"); searchForThingy("Foo"); assertTrue(isPresentInResultList("Foo")); } Re-use makes tests less fragile

Use your code directly Prepare your search tests using model API FolderBean fb new FolderBean(); fb.setParent(FolderBean.ROOT); fb.setName("foo"); fb.createNewFolder(); // adds a folder to the DB selenium.open("/search"); selenium.type("query", "foo"); selenium.click("search"); assertTrue(selenium.isTextPresent("foo found"); Your tests and web app are written in same language. A class per test vs. A class per page Do create a class for each test this inherits from TestCase contains the ‘flow’ of the test If the same pages are used by multiple tests create a separate hierarchy of classes, one per page inject the test into the page to access Selenium public void testWorkflow() { ! WelcomePage welcomePage new WelcomePage(this); ! welcomePage.selectDailyView(); ! DailyView dailyView new DailyView(this); ! dailyView.selectLocation("LDN"); ! dailyView.clickOk();

JUnit vs. TestNG JUnit is “opinionated software” public void setUp() { log("setup"); explicitly prevented Dependencies between tests} are Separate tests are testing separate public units void testFoo() { log("foo"); every test method Everything gets torn down after } browser Constantly starting/stoppingpublic void testBar() { TestNG has dependsOnX } log("bar"); public void tearDown() { log("teardown"); } » setup foo teardown setup bar teardown Summary Use Selenium when it makes sense when you want to reproduce a user’s interaction with your application in a real web browser when you depend on the browser (AJAX) Do consider presentation model and HTTPUnit Use Selenium for Integration Testing Use Selenium in your development environment Use the features offered by your language

What is Selenium? Test tool for web applications Runs in any mainstream browser Supports tests in many languages Selenese (pure HTML, no backend required) Java, C#, Perl, Python, Ruby Record/playback (Selenium IDE) Open Source with corporate backing Lives at selenium.openqa.org Record a test in Selenium IDE Show same test written in Java .

Related Documents:

of consumer-driven contract testing (CDC testing). This example will dive into how automated testing is beneficial for software built with a microservices architecture. As automated testing continues to shape software development, more and more companies are investing in test automation strategies. Automated testing is equipping

trained in QA testing. The goal of manual testing, like automated testing, is to find errors in code, potential bugs, and to ensure performance. Any test can be manual, but manual testing takes more time and money than automated testing long term. Manual testing generally decreases return on investment (ROI) because it requires replicating

What is a Testing Framework ! A testing framework or more specifically a testing automation framework is an execution environment for automated tests. It is the overall system in which the tests will be automated. ! It is defined as the set of assumptions, concepts, and practices that constitute a work platform or support for automated testing. !

GN3 Quality Assurance Best Practice Guide 4.0 Last updated: 07-09-2012 . 4.4.2 Non-Functional Testing 13 4.4.3 Security-Oriented Testing 16 4.5 Principles of Software Testing 17 4.5.1 What to Test For 17 4.5.2 How to Test 18 4.5.3 Testing Improvement from Bug Fixing 20 4.6 Tools Used in Testing 20 4.7 Testing of Web Applications 21 4.7.1 Performance and Stress Testing 21 4.7.2 Automated .

WHY IS THE TESTING METHODOLOGY BROKEN? » OWASP Web Service Testing Guide v3 It's good for web application testing "in general" It's the "gold standard" It's outdated in regards to web service testing Missing full coverage based on a complete threat model ‒ Examples: MiTM, Client-side storage, host based authentication

Table of Contents Introduction 1 Brief Background on Automated Vehicles 1 The Role of State Highway Offices 4 State Behavioral Highway Safety Programs and Partnerships 4 State Highway Safety Offices and Automated Vehicles 5 Current State Automated Vehicle Activities 6 Legislation 6 Testing and Deployment 6 Automated Ve

Therefore, it is important to understand the performance of web application for any organization and people. So, necessary to know how the load testing is used to test performance of a website. Introduce to this system to distribute automated load testing of web application using AppPerfect load test tool. Generally, the process of

EN 571-1, Non-destructive testing - Penetrant testing - Part 1: General principles. EN 10204, Metallic products - Types of inspection documents. prEN ISO 3059, Non-destructive testing - Penetrant testing and magnetic particle testing - Viewing conditions. EN ISO 3452-3, Non-destructive testing - Penetrant testing - Part 3: Reference test blocks.