17

So I've been testing web based analytical software now for the past 4 years or so with mostly manual techniques. But for 2015, I've set myself the goal of getting setup and start writing automated tests and to introduce automated testing into my company.

I've done a little research and it seems that Selenium is quite big when it comes to writing automated tests, but most of the tutorials I've come across reference the Java language.

Some questions:

  • Is Java the primary language used for Selenium tests?
  • Do you recommend it over C# ?
  • Wat is the process of writing test scripts?
  • Are there Frameworks that I should use that can make the process even easier?
  • That question relates to someone wanting to get started with testing/QA. – Keva161 Jan 13 '15 at 23:10
  • I've used C# in two different companies for Selenium, and it works just fine. You can go pretty deep in terms of UI interaction, don't worry about that. – FDM Jan 14 '15 at 6:28
  • 2
    For the language of choice, typically you would try and use the development language that the company uses. This allows for you to be able to reach out for assistance when needed and have someone take over your efforts when you are no longer with the company. – Paul Muir Jan 14 '15 at 16:40
  • 1
    Do you mind if I clean this up a little and make it the canonical "How to get started in Selenium" question? I can start working on a comprehensive answer – Yamikuronue Jan 27 '15 at 16:41
10

To broadly address your question, just pick some test cases with simple interactions that aren't very dynamic and automate those. Trial, error, and practice will get you there.

Is Java mostly used for Selenium tests? Do you recommend it over C#?

According to StackOverflow, there are more Selenium tagged questions in Java than any other language (as of this writing).

That being said, getting into programming is difficult enough that you should pick a language that's easier learn (Both Python and Ruby have Selenium). The marginal improvement of Java/C# with Selenium is far outweighed by their difficulty in learning.

Also, what is the process of writing test scripts?

Honestly, a lot of the grunt work is getting Selectors for your code to use. Selenium needs a way to know which element to interact with, so you use Selectors to identify the element. You'll be getting nitty-gritty with xpath and/or css.

As you improve you'll struggle more with code maintenance, which is a good problem (you've written enough automated tests that you need a better way to manage them)

Are there Frameworks that I should use that can make the process even easier?

It's hard to know if a framework saves you more work than it creates. Why not try writing some simple test cases until you start asking yourself "I wish there was a framework that could do ____"

Finally, don't get sidetracked by writing perfect code. Just keep doing it and you will get better.

12

How to get started with Selenium: A Brief Overview

So you want to automate browser-driven tests, and you're not sure where to get started. You've heard of this "Selenium" thing, and you think it's what you want, but you can't be sure. Fret not! Here's a quick rundown of what you're looking at and how to get going. This is mostly adapted from two sources: the official documentation and my blog post on the subject from a short while ago.

Selenium IDE, Selenium RC, and Selenium Webdriver

There are three products with the name "Selenium". You can safely disregard the old Selenium RC product if you're just getting started, as it has been superseded by the new "Selenium Webdriver" product. That leaves Webdriver and Selenium IDE.

Selenium IDE

Selenium IDE is a firefox plugin that records simple automation tasks in the browser and saves them as XML so they can be played back. It is great for one-off tasks like recording the steps to repeat a bug report, but it produces output that is difficult to maintain in the long run, so you don't want to use it as the only tool for a large automation project like a full regression suite.

WebDriver

WebDriver, on the other hand, has two components: a client and a server. These can be bundled together if you're always going to execute your tasks on the same machine the code is running on, or you can use RemoteWebDriver to set up a dedicated machine for test execution separately from the machine used for code execution. In practice, this can be very useful if you want to, say, run the tests in a VM so you don't have browser windows popping up and closing all over your desktop while you're trying to debug something, so I always use RemoteWebDriver and just start a local instance of the server if I'm only running from one machine. But you can do as you please.

What language do I use?

So you've decided to use Webdriver, rather than Selenium IDE. Good for you! Now you have to decide what language you want to automate your tests in.

I have good news here too: ultimately, it doesn't matter. Pick a language that fits the tooling around your process, or, barring that, a language that you're personally comfortable in. Many people use the C#.net bindings or the Java bindings, but many more use python bindings. The libraries are the same across all bindings; the only thing that changes is the exact syntax of calling methods.

What do I automate?

Webdriver is very good at driving browsers, but it's still an unfortunate fact that GUI-based automation is slow and fragile compared to headless automation. Wherever possible, try to automate at a lower level, for example, a unit test or an integration test. This will provide much more stable, rapid tests.

That said, there is of course value in automating against a GUI. You should automate functional tests that are stable and provide value to your organization. Ultimately, only you (and your team) can decide what's worth automating. I suggest starting with simpler test cases so you can get a feel for how much work it takes to automate a script.

How do I structure my project?

My first functional test frameworks were for desktop and ATM software; I’d never heard of the PageObject concept, but I learned by example how much easier the tests were to read if you had a detailed framework. This also allows for separation of concerns with regards to staff: let those who are good at programming work on the framework, and those who have a good eye for test cases work on the test code itself by calling framework methods. The framework should contain everything needed to interact with the software under test, packaged up in clear, easily read methods like mainWindow.openHelp() or fileDialog.chooseFile(filename). Your test author shouldn’t have to know about things like button names or window handles or xpath locators in order to write a test; they should use something very close to human language, so it’s easy to verify that the automated test matches the manual test case.

In Webdriver, this is accomplished by using PageObjects. In essence, a PageObject is a class that represents a single page or portion of a page in your web application, akin to a class representing a screen or a dialog in desktop automation. There is a PageFactory class that can automatically create elements in your PageObject on the fly when they are required based on annotations; I suggest reading through the documentation, because this is a really neat little time-saver for creating your framework. I also like to create a helper method that will take in a url and return the PageObject that that URL represents, therefore allowing the test to figure out when it’s ended up on the wrong page by mistake.

What information do I need about the application?

The good news is you probably don't need a developer handy to figure out how to interact with the page! The bad news is you'll become intimately familiar with css selectors, xpath, and the structure of the DOM. If you're not very web-savvy, you may want to partner with a developer to help figure out what selectors you can use to get to elements. If you use jQuery, you can often test out your css selectors by passing them to the jQuery object and seeing if any elements are returned.

Where can I find more information when I get stuck?

You can always search this site and StackOverflow for questions (or ask one if the information is not already covered), but you'll also want to familiarize yourself really well with the documentation. There are also many books on the subject (such as this one) if you learn better from books, and you can find online web courses (like this one) if you learn better that way. Ultimately, test automation is one of those subjects in which you'll always be learning new tricks, and every project will build on the successes and failures of the previous one. Good luck!

  • This should be the accepted answer. – Dan Dascalescu Aug 5 '15 at 10:58
5

Start by looking for testing tasks that require a lot of manual effort and do not change from one release to the next. This is especially important for UI automation; if a web page changes frequently, you will spend so much time updating your automated test that it will have been faster to test the page by hand.

Note that there are often ways to use automation that do not involve testing web pages. For example, testing often requires creating test data. If you can write something that inserts data directly into a database rather than creating the data through your web interface, you will save time and reduce mistakes.

1

The best way to start test Automation is to have the below things:-

1) Sound language knowledge (Java/C# .......etc) 2) Good understanding of locators ideally XPath , not the ones copied from FireBug but custom hand written ones. 3) A stable framework design, start with basic design and then improve using best practices. Try and used xpaths embedded in functions/methods like so.

JAVA :

  protected void selectElementByVisibleTextAndFielsetName(WebElement parentElement  , String visibleText , String fieldsetName){
        try {
            WebElement element = parentElement.findElement(By.xpath(".//div/label[contains(.,'"+fieldsetName+"')]/../../div/div/select"));
            Select select = new Select(element);
            select.selectByVisibleText(visibleText);
            logger.info("Selected text is :" + visibleText);
        }catch (Exception e ){
            e.printStackTrace();
            takeScreenshot();
            logger.info("Screen shot has been taken !");
        }
    }
0

Is Java the primary language used for Selenium tests? Do you recommend it over C# ?

I prefer C# over Java mostly because Eclipse doesn't come close to Visual Studio. For a professional Tester/Test Architect/Test Programmer Visual Studio Ultimate is the best. However, both Ultimate and Professional editions are 100% integrated with TFS which brings ALM (Applicaiton Lifecycle Managment) into the picture. This means that via a fantastic Bug queue the QA Team can bring a disciplined development effort by using TFS as a just a bug queue at first.

From there everyone will see the Agile nature of TFS and will reject it at first as is normal for Waterfall based shops. But if the QA team can be the catalyst for getting the entire shop into Agile the benefits to the QA team are huge.

Visual Studio "speaks" Selenium via a NUGET package download. If you want an IDE that is the best out there then C# is the only choice.

protected by Community Jan 29 '18 at 12:36

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.