How does Protractor compare to Selenium WebDriver?

My experience so far in development roles has been with the .NET stack so when I was asked to pick a tool to implement UI automation, I had using Selenium and C# in mind. However, due to the technology of the systems I was automating, I decided to investigate Protractor.

Things To Consider

I must admit, I was pretty hesitant about trying Protractor. But, I had a number of factors to consider which meant that I had to give Protractor a chance.

I needed to make sure that the tool that we selected fulfilled the following criteria:

  • Setup and writing the tests needs to be implemented quickly
  • Needs to be able to implement a good and extendable project structure
  • Needs small learning curve as the team are both new to the company and will have enough new tech to learn
  • The tests need to run faster than it takes to run them manually
  • Developers need to run these tests via command line
  • Results need to be displayed clearly

Setup and writing the tests needs to be implemented quickly

This was important because we are only a small team and we have a lot of work to do now and in the future. Being able to set up the test frameworks quickly will means we can get this done and be confident the areas tested by the frameworks is covered leaving us with the manual tests and exploratory.

Setting up a Protractor project

Luckily, setting up Protractor was extremely simple. Using the following 3 lines sets up Protractor easily (you do need to have npm installed first but if you don’t, that’s another quick installation).

npm install -g protractor
webdriver-manager update
webdriver-manager start

Installing Selenium into a project

Thanks to Nuget Package Manager, installing Selenium is now a lot easier than when I first started automation.

You just need to install the Nuget packages, Selenium Webdriver, Selenium Support and WebDriver.ChromeDriver into your project. Once you have these, you are ready to go!

Needs to be able to implement a good and extendable project structure

At this early stage in the company, we’re not sure how many more that’ll be added to the team. However, it’s important to create a framework that can be extended and easily maintained.

I’ve been using the Page Object Model design pattern to structure my project. I’ve done this because it’s easy to read, easy to replace classes and methods, and everything is contained and broken down into small bite-sized chunks. So this is (basically) the structure I have been using for my project. I’ve got a few minor objections to making the Page classes static, so I haven’t followed this to the letter, but the principle is there.

Creating a good Protractor project structure

I found that the examples of using the Page Object Model design pattern  were a bit misleading.

The point of using this pattern is to separate the functions into different files so that everything is less dependent and extendable. However, the examples of this had all the code to run a test in one file. So it was good if you wanted to learn the basics of the page object pattern but not if you wanted to use it properly.

I set about implementing this in the way that I am used to and then I ran into some issues when trying to separate these out into different files.

After I overcame these issues, I learned that if you want to use functions from one file in another, you need to add this into the main function of the file that’s referencing the function:

var homePage = require('../Pages/HomePage');

You can also add this at the top:

require('../Pages/HomePage');

Then you need to add this at the end of the file that contains those functions:

module.exports = new HomePage();

This allows you to use the “require” command to call that file and enable it’s functions to be used in other files.

Once I got my head around this, I used the examples of locators on the Protractor website to quickly write the bulk of my tests.

Page object model and Selenium

Because of my experience with C#, setting up the Page Object Model in a C# project was a lot easier. Plus, there are a lot of experienced automated testers out there with video tutorials to help if I ever got stuck. needless to say, there was no issues putting this together.

Needs a small learning curve

As our team is new to company and will have enough new tech to learn, it’s important to make sure the tool isn’t too complex to learn or it’ll eat into the time we need to spend doing other things.

Struggles with Protractor and JavaScript

The team were all unfamiliar with JavaScript so progress was slow to say the least. I got tripped up a few times with the unusual syntax, as I haven’t used it for years.

Using the protractor commands, like locators was also new. So even though the framework was built on Selenium and locators looked familiar, implementing them still want straight forward. Despite knowing what i wanted to do with a locator, I had to keep looking up the correct syntax to add them to my test.

Using asserts that aren’t standard to MSTest or NUnit was also took some getting used to and lots of searching on Google.

There’s no doubt a steep learning curve here. Not complex, but just time consuming. And I’m not certain whether I or my team, have enough time to learn all of this as well as all the other parts of the system and tools in this new company.

Learning curve with C# for my team

Putting my own selfish reasons aside, my team is used to using object-orientated programming languages. So picking C# to carry out the automation, was a lot easier for them to pick up and progress using.

This smaller learning curve also made this switch a much more enjoyable experience for my team.

The tests need to run faster than it takes to run them manually

The reason why we automate some tests is because these tests are run repetitively, they’re setup is rather complex to carry out every time or they take a long time to run. So, making sure the tests that we write run faster than if they were carried out manually is highly important. If not, we’re wasting time, not saving it.

Speed of Protractor tests compared to Selenium

I must say, the small amount of tests that I have written are run very fast using Protractor. Unfortunately, out of the box, Selenium is a lot slower.

For this comparison I ran the same amount of tests for each project. The Protractor tests ran for approximately 13 seconds while the Selenium tests were running for over 40 seconds 🙁 There are ways around this like that I have investigated like, running the tests in parallel (which reduced the test time to around 16 seconds) and other ways to refactor the code to improve the performance, but clearly Protractor wins by miles in this aspect.

The Choice I Have to Make

The decision that I have to make is whether being able to implement tests faster, but slower running tests is more important than implementing tests slower but that will run faster.

Using Protractor has been a roller coaster ride so far that I think will only get progressively more difficult before it gets better the more I use it. I did get through it though.

There’ll always a little nagging voice at the back of my mind telling me that this will be so much easier with Selenium and C#. However, learning how to implement Protractor has expanded my testing capabilities already. And although the tech of the project shouldn’t dictate the testing tools you use, I think trialing this was beneficial to at least consider the potential benefits.

Overall, I’m leaning more towards sticking to what I know. Performance improvements are always being made to tools. Selenium tests may get faster in the future and if not, there are a lot of performance improvements and code refactoring that I can implement to help with this.

What Do We Mean By Testing?

Testing is an area of development. A product or service is measured against a number of criteria at different stages of the development cycle. This is measured against the original spec, goal or intended use. Testing can be carried out manually by individuals or automated by computer systems. The automated scripts that run the systems are written and also maintained by individuals.

Why Choose Automation?

It may take longer to set up initially, but automated testing may save a lot of time and money in the long term. There are various arguments for and against automated versus manual testing. It will just depend on the task needed to be carried out and the industry as to which method is more suitable.

When I was at university not a lot of emphasis was placed on testing and the roles within this field. More attention was on the career path of the developer. But, the roles within testing can be as technical as that of the developer and just as important.

Depending on the company you work in, the job of a developer and tester may blur. You may need skills useful for either role in order to do your job effectively.

What Qualities Make You A Good Tester?

These aren’t all the qualities that you need to be a good tester but they’re certainly highly important.

  • The ability to communicate efficiently and effectively

This includes between technical (developers and other testers) and non-technical (business) members of your team. Both written and verbal communication skills are important to improve and perfect.

  • High attention to detail

You should be able to pick up minor issues as well as the glaringly obvious ones and be able to reproduce them correctly. The more issues you find and help fix, the higher level of quality the product you ship has.

  • Being able to pick up new software and languages quickly

Like most areas in IT, the tools that testers use are updated and change very quickly. As well as the tools you will use on a daily basis you may need to be able to use the tools that the developers in your team utilise.

Why Specialise In Testing?

The field of testing is extremely varied. As I mentioned, an automation role in testing can be just as technical as a role as a developer. But if you’re not into technical jobs you can still be a valuable manual tester. Manual testers frequently carry out exploratory testing which is extremely essential and something that automation can’t replicate.

As testing is the last stage in development before the product is released to the customer or to production, testers are responsible for identifying issues that could impact the reliability and use of the product. When these issues are found testers work with developers to get the issue fixed and retested to ensure the problem is solved and that nothing else is broken. Testers are the gatekeepers of quality.

Is Testing For You?

If you enjoy ensuring that something is of the highest level of quality, testing could be for you. You need to be willing to carry out some tasks that may be long and repetitive. However, others may give you a unique perspective into the development cycle and could expose you to different fields. For example, you could get more exposure to business analysis when you’re trying to determine the expected results for test cases. Or, exposure to software development when you’re writing automation or other technical tests if you’re utilising test-driven development or behaviour-driven development.

Ultimately, it’s a very satisfying role knowing that you’re the one upholding your brand’s image by ensuring a high level of quality.