What can be the best design strategy to follow for designing an automation frame work for a Web App using webdriver (python)?
-
I have been given a task of automating an enterprise website. I am starting the project from scratch. I have zeroed in on using Selenium WebDriver with Python for this. Since last few days i am going through various blogs on the internet suggesting to use Page Object model. If people who have experience on this give inputs on the best model to follow keeping in mind code re-usability and robustnus, will be highly appreciated. Any pointers to any resource suggesting the same are also welcome.
-
Answer:
I have developed a testing framework based on Selenium WebDriver for a client, to test a web application, and can share the lessons learned. The framework and the tests were written in Java, but mostly the same principles should apply. I will use pseudo code below to illustrate my points. Usage of the Page (or View) Objects pattern The basis of the page objects is to separate between the test code and the definitions of how to access the element (i.e. the element selectors). Those shouldn't be limited to actual web pages, but any view, or part of the view in the web application. For example: The Login Page itself, A navigation bar that appears in multiple pages, A date picker control. Take each view component like that and wrap the element access. Allow composition and inheritence of For example: class BlogPost extends BlogPage TagList postTags Searchbox postsSearch ShareDialog clickShareButton: .... Have parametrized view objects for reusable components, that in each container view can have different settings and selectors: DropDownMenu (itemsList, parentDivSelector) Log simulated user interactions in the components, to understand the executed script scenario, and where the tests failed. (more about reporting coming up...) class Button (name, selector) click: testContext.log("Button {name} clicked") Element(selector).click() A test context to log additional data toThose are not unit tests, but complex user scenarios. The tests should be able to save additional data to it. You should then be able to display it in the reports (below) under the correct test. Some examples of kind of information is used to save under the executing test context: Screen captures on explicit calls to save them implicit screen captures in the end of or in errors Logging messages, in different levels (info, traces, etc) Time stamped information for all the above Test environment metadata: Browser, OS, etc. Web automation tests reportsAs stated, the kind of information needed to understand what went wrong with the test scenarios, a different report than a simple unit test report is needed. It needs to report the data you logged in the text context in a scenario like fashion. For example: Login test Browser: Chrome 30 on Windows 00:00 Starting new browser session 00:00 Opening home page 00:01 Clicked login 00:05 Navigation to login page completed 00:05 entered "amitay" in username textbox 00:06 enter "secret" in password. 00:06 [screen shot] 00:08 clicked submit button 00:10 Navigation to dashoard page completed. 00:11 ***Error: expected url to be .... 00:12 [screenshot] Additional test runner capabilitiesYour test framework (either your own implementation or the one you are leveraging) might need to support additional capabilities: Parallel test execution (web automation using selenium can be slow...) Dependent tests (run testC if and when testB and testC are completed Parametrized test (for example, to run the same tests on different WebDrivers (i.e. different browsers) Creating a new browser session, and continuing one from a completed test. Configuration The tests might run in different configurations: Continuous integration server, development, nightly tests, per commit tests. Some configuration that you might need: Web driver instance creation settings 3rd party (such as sauce labs) authentication Which tests to run Which tests to run on which browsers Timeouts Some other suggestions Consider using a 3rd party "Remote Web Driver as a service", such as browserstack or saucelabs. The main advantage is saving the huge pain which is maintaing a stable multiple browser environments. Additional advantage is the additional features they add (such as recorded videos, selenium logging). Write some tests as you write the framework. The issues you'll encounter will teach you a lot about what are the actual needs. Don't write too complex test scenarios. Web drivers test in real-world can be quite fragile, and too complex tests may lead to many false negatives, when it's the test which failed. Consider when it is better to write javascript unit tests instead of browser automation tests. They tend to be much more robust. A tip for java developers: Give testNG a chance. I found it very powerful and extendable, and is a great test harness for more than unit tests. This ended up rather lengthy, more of a post than an answer. If you've read it this far, it might be time to go write some selenium tests! Good luck!
Amitay Dobo at Quora Visit the source
Other answers
if your can use php, have a look at Behat. It's a framework for behavior driven development. Its main advantage is that you can write English statements which can then be translated to code. For example your test code would be written as Given I am on the home page When I enter xyz in the search bar And I click submit Then I should see pqr This can then be translated into actual code. The above is an extremely simple example and by no means demonstrates the full potential of Behat. Visit http://www.behat.org to learn about what more it can do for you.
Kayomars
I recently designed a few of these "frameworks" for various projects. They are much more effective when automated testing is considered before the application is built as the coding would have been designed to make the application easier to test. I think you need to take a step back from tooling up. Get more requirements (What coverage is there, currently, where are places to start, e.g. are there features with alot of bugs. What browsers do I need to support. What skills do I have as I'm writing the tests). Be mindful that trying to run all your tests via a browser take longer to run and doesn't actually make too much sense if the logic is lower down. The "Web" tests These should be built on a solid test bed of unit tests and service tests. I would look at the http://martinfowler.com/bliki/TestPyramid.html and the Ice Cream cone anti-pattern (http://watirmelon.com/2012/01/31/introducing-the-software-testing-ice-cream-cone/) before you get started. Hope this gives some food for thought
Martin Gollogly
Some tips I'd like to share: Check out nosetest. If you aren't already using a more powerful testing framework, it's very much worth looking in to. You'll be glad to have flexibility in grouping tests and having some of the nice prep and cleanup features. Plan from the start to use something like Jenkins (my personal recommendation) to launch your tests. There are lots of reasons for this, but here are a couple of points: From the Jenkins web UI, anyone can allowed launch any test job you setup. You can very easily have tests launch based on code check-ins or as a result of a new web server deployment (e.g. new QA or DEV code deployed) Have your test suite read a config file on startup. This will let you adapt to different environments (starting urls, base server names like qa vs dev, and any wide array of alternatives you may need at test startup) Build classes to represent a web pages and modules on a page (header, login dialog, data output element etc) The obvious advantage is code re-use, but it gives you a great abstraction for actual test writing vs app interaction. Building on (5), write your tests as simply as possible, and completely separate from the classes in (5). Avoid putting app related logic in the tests themselves. The test scripts should implement the test classes so it's obvious what they are trying to do, are readable, and are not the piece of your tests you test to be troubleshooting. For example: is_logged_in = login_dialog.login("someuser", "some password") if(not is_logged_in): print("[FAIL] Something went wrong with login ") # you probably want an assert here, too, to fail this test else: print("[INFO] Login succeeded") # ... continue obvious workflow here... That login_dialog should be a class that does all of the necessary nitty-gritty to ensure a good login process, all hidden from the test script.
Robert Arles
I would request to construct a parameterization on the object recognition and pass the objects through excel file if possible and maintain the files with latest objects.For more information:http://www.amazon.com/Software-Automation-Testing-Secrets-Revealed/dp/9383952954/
Narayanan Palani
Related Q & A:
- How to call a web service using HttpWebRequest?Best solution by Stack Overflow
- What are some best practices to follow when designing for users completely unfamiliar with computers?Best solution by User Experience
- What would be the best book to Help me learn web design in C# and asp.net?Best solution by Stack Overflow
- Where can you work as a Web Developer / Web Designer?Best solution by Quora
- What would be the best design for the olympics?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.