I have to admit that I fell in love with Selenium for its record-and-play feature as well as the testcase generation functionality for those recorded actions from the IDE. But I am still hesitated to advance to the implementation stage because of the incidental details (e.g, locating the events with DOM, xpath..etc) that are built into the testcase during the recording, which could make the testcase failure prone whenever there is a html change once it's imported to the RC. I fully understand that it's a part of testers' jobs to adjust the expected results from time to time as part of the regression test, but I also do not wish the time spent on this is larger than the time that takes to do the manual test.
As far as I know Selenium with Robot framework has the keywords form of testcases. My guess is it allows us to extract the incidental details into various keywords, which could make the testcases being adjusted easier and are more maintainable. (Please correct me if I am wrong)
It will be appreciated to hear suggestions on how an effective UI automation environment should be setup. Should I just use Selenium RC or Selenium with Robot framework? And why?
Thanks in advance
You are absolutely right that incidental and often changing details in the produced scripts is the biggest problem of record-and-playback automation. You can obviously remove the details from the scripts after recording, but in my opinion it's better to build reusable libraries and code scripts manually from the start.
A good alternative for coding scripts using "real" programming languages is using some higher level automation framework such as Robot Framework that you mentioned. As you speculated, Robot's reusable keywords and also variables make extracting details away from tests very easy. The test cases in SeleniumLibrary's demo illustrates this very well and the demo also shows how to use Selenium through Robot.
You also asked about Sikuli. I've never used it myself but it sure looks interesting. You might be interested on this great how-to that explains how to use it through Robot Framework.
Our company is using Fitnesse, not Robot, to control Selenium however, we have the same problem. We switched from making assumptions about the DOM to only accessing elements by ID. Since this is cumbersome in Fitnesse we are currently working to add a Selenium backend to our own Framework (which previously only had backends for Java and Smalltalk).
So, by requiring that elements with certain ID's are present in the DOM we will of course break our tests if someone removes the elements from the page; however, we found that this behavious is very useful as this enforces the contract the tests made with the implementation and it is a good thing we find missing elements as soon as someone broke the implementation.
In addition, it is good practice to keep UI automation skin-deep: Only test what is present on the page with Selenium and test the business-logic by calling the underlying functions directly.
Related
I need knowledge about how to develop a framework for web automation using selenium webdriver. please give me ideas and steps to create framework.
Now I'm able to locate all the web elements on web application by just writing a one big bunch of TestNG test code by using #Test annotation.
In my web application there are many places where I can reuse the code to do the same operation across all. So help me out to develop a best framework.
It depends on the problems you are facing.
If you want to clearly separate writing scenarios from editing the logic (for instance, you work in a team with testers who aren't software engineers but know Java and algorithmic well enough to construct elaborate scenarios from small building blocks), then it would be wise to introduce a layer of steps classes containing methods like openTheUserMenu(), fillTheFormDetails(String name, String surname, String address) etc.
If you write tests for some dynamically changing or developing project with UI elements changed or refactored often you would definitely need Page Object pattern to encapsulate the UI logic (so that in your steps you would write just mainPage.selectDateOnCalendar(Date date), and all the necessary typing and clicking would be written out in the page's method).
Finally, if you work closely with your client and need to formulate the requirements in natural language first, and then translate them into more formalized language for developers to implement the required functionality, you would need to use BDD and appropriate libraries like JBehave with scenarios written in phrases in high-level almost natural language mapped onto test methods in Java.
In short, this is it. If you want details, there are plenty of materials on the Net as was mentioned already. Just remember - you should invest in elaborate framework only if you really need one to solve the problems you are facing.
Hi I am very new in Selenium WebDriver and I am at a cross roads right now. I took one module of the application I am working on and wrote the scripts for it. I ended up with a lot of java classes. Now,
How do I incorporate that into the framework?
Am I doing the right thing?
Is it advisable to hard code everything before incorporating it into the framework?
Please help, your input will make a huge difference. Thank you!!!
You have done correct thing since you are new to selenium. The next step is to create a very basic framework that can support keyword or data driven approach. You can also go for page object model or page pattern using factory. Again you have to evaluate those frameworks with respect to your project complexity and pick the correct one and develop.
Hard coding things are not good, you need to try to get rid of hard coding ASAP otherwise tests will not be manageable as test suits grows.
A good test automation framework should have minimum following capability:
Scope of code re-usability using helper classes
Capable of logging information
Modular
Data driven.
If you want, keyword driven
Well formatted object repository.
Choose a good unit testing framework and use it.
Hope this information will help you.
Sorry for this weird question.
Actually we go for selenium-webdriver to make manual test simpler,but what I felt is, for finding each and every webelement itself a hectic job. I actually do 'n' number of test to test my selenium code.
So, how can I make it simpler.
Thanks in advance!!
With my current experience with Selenium testing:
write your own methods
If you have repetitive sequences of actions to check something - pack it in your own methods like: find, click or find, get text attribute, assert if true etc.
make use of loops
Need to assert if text attribute is correct for N elements? Count number of elements, put your "testing" method inside loop for N repeats, compare against control-data stored in list/array etc.
use all what testing-framework can provide
In my case I test with the help of NUnit. If I have set of similar or even identical tests, why not to use [TestCase] instead of [Test]?
refactor / simplify
If you realize during or after test development that some parts of code are redundant - just replace them with corresponding methods you created instead. Code will get much shorter quickly and will be much easier to update if needed.
For me, the easiest way to find an element is by using css selectors. It is more natural and you can easily test your css selectors on chrome devtool by using the following construct like jquery, $('.classname').
BTW, I just created a small project to bootstrap a selenium project. You might want to check it out as it used shortcuts for selectors and I feel that it is more natural to have it that way, e.g. selector starts with '#' then us By.id, starts with '=', then use By.name.
Here's the project url: https://github.com/codezombies/easytest
You can use the tool fire-ie browser, this will help recognising elements without navigating to inspection page.
From below link, tool can be downloaded
http://toolsqa.com/selenium-webdriver/fire-ie-selenium-tool-ie-browser/
Another option is use Selenium IDE to identify the element. This is suggested option only for the non-technical users. Now Selenium IDE is available even on Chrome.
Selenium WebDriver is the most mainstream computerized test structure being utilized in programming improvement these days. Since it underpins all the principle programming dialects, for example, C#, Perl, Ruby, PHP, and JAVA, you have the opportunity to learn and make test code in any of these dialects. Selenium WebDriver+JAVA is the mix that is utilized the most. Obviously, information on HTML, javascript, and CSS is significant. Remember that an analyzer's employment is active. There will be numerous acceptable books on test mechanization. Nonetheless, the best preparation and range of abilities comes from dealing with genuine tasks.
Web advancement has expanded three-overlay contrasted and what it was years back. Various organizations are selecting to create sites to show their essence on the web. Also, testing is a significant piece of this web advancement measure. Concur? Obviously, it is. Most likely on that. In excess of a billion sites are live right now.
We see that various instruments are being delivered to assist with the turn of events and testing measures. On account of the web advancement specialists who are exploring and concocting good thoughts once in a while. You can discover various tooling alternatives on the lookout. Heaps of instruments are accessible to help you make your testing cycle simple and straightforward.
In a ton of testing instruments accessible out there, Selenium is perhaps the best device to date. The developing prominence of Selenium is a result of the wide scope of highlights that it offers. Selenium is open-source. You can download it liberated from cost. It is easy to comprehend and simple to utilize. With Selenium, you can play out your test on an assortment of programming dialects, for example, C#, Java, Python, etc, utilizing its Web Driver API. You can utilize it for mechanizing cell phones, including Android and iOS through Appium separated from for internet browsers.
Steps are as follows:
Choosing a Framework for Testing
How Do You Choose a Programming Language
Choosing a Unit Test Framework
Designing the Architecture of your Framework
Choose a Mechanism for Reporting
Building the “Selenium Test” Component
I am developing a library that extends Selenium 2 with some custom commands. The library should be usable from Selenium's Java and Python bindings as well as in Selenium IDE. From my research, these three target bindings should cover at least 80% of all Selenium 2 scripts.
In order to implement my custom commands for Selenium IDE, I think I need to write a plugin for it in JavaScript.
My question is this: If I already have an implementation of my custom commands in JavaScript, is it safe to re-use this implementation for the Java- and Python bindings of my library?
I am thinking of an approach that injects the JavaScript implementation of my commands via WebDriver#executeScript. Here is a pseudocode implementation of what I am thinking of.
In Java:
public void fooJava() {
executeScript("Inject code.js");
executeScript("fooJavaScript();");
}
In code.js:
function fooJavaScript() {
// Implementation of command "foo" from Selenium IDE plugin.
}
So, to execute my custom command fooJava() in Java, my library's code.js would be injected into the browser via executeScript. This would contain a JavaScript implementation of foo, say fooJavaScript. In a next executeScript call, this fooJavaScript would then be called.
While this approach would prevent me from having to implement my custom commands three times (Java, Python, Selenium IDE), I have a few concerns:
When I inject my code.js, am I in danger of destroying global state of the web site?
To which extent can I rely on JavaScript? Will it work if an alert dialog is present? In practice, how many of the drivers used with Selenium do not support JavaScript? Eg. HtmlUnit?
Will this work in all major browsers (somewhat recent versions of IE, Chrome, Firefox, Safari)?
Your real-life experiences with this would be much appreciated.
Principle states you should not be using JS as your testing mechanism if you are just delivering a payload with WebDriver.
WebDriver = integration testsJS = if you want unit tests
I don't know your use cases exactly, but:
If you're trying to run integration tests, stick with WebDriver to best simulate user interaction. You also avoid cross-browser JS issues in the future by relying on the WebDriver hooks to interact with the page, as in, you are better off relying on the community to provide reliable basic DOM interaction APIs for each browser. If you can't trigger test conditions with browser interactions, you're getting into unit/code testing territory instead of integration testing.
If you are trying to run the JS for sake of essentially testing a single function or piece of code rather than an integrated interaction, you are trying to run a unit test. Unit tests are best done in JS with something like Jasmine (name any framework here).
Reasoning:
Integration tests should be written to be as implementation independent as possible. You should not need to know a function name to trigger an integration test, since someone might change the function name in the future or restructure the code.
Since you are filling a QE/tester role, you do not want to be responsible for breaking integration tests when code changes - if you use this and are responsible, then you will need to change a test every time there is a code restructure.
Sources: Experience as a QE in 10,000+ employee software co.
At present I have a framework which support firefox browser only. Now I am going to enhance my frame work so that can any give your ideas to me by suggesting your thoughts.
At present I am using Selenium Java, Hybrid framework, maven setup, Webdriver surefire reports.
So
1) If I want to run test cases on multiple browsers and multiple version of browsers parallel. what is the best approach?
Thanks
R
Well you need to setup the grid for parallel runs.
You need to make your browser launch code depend on a configurable parameter.
You can either take it as a parameter of the testng xml or make it as a system argument.
Depending on the value of this parameter, your listeners or your launch code (I am hoping that would be isolated since u mention a framework is in place) should be able to use this parameter to make a decision on what browser/node to launch.
For parallel runs, it would be better if you can use some framework. We use testng as the framework which supports parallel runs with good results.
I know you dont want to hear it, but best way actually is trial and error
Your site is going to behave differently in different browsers. So you will have to update your script for almost every browser and you will have to do it manually
Browsing speed is going to be different. Maybe invest in Implicit wait into your script
And yes, you are going to hate it.
My "best approach" is:
Implement the script for one most used browser and automate as much as possible
In other versions do manual shakedown of most crucial functions
Communicate with business to write somewhere that some obscure browsers (like IE 6) are no longer supported so you have more time to polish the script