6

I have designed a hybrid(keywords and data in same excel sheet) framework using WebDriver+Java+TestNG+Maven. I am using PageFactory, Singleton Pattern . I am using different type of HTML locators in my framework like id, css, xpath. I run tests on UNIX environment.

I was told that using id instead of xpath is faster. But how do we measure it, because when I use xpath and when I use id in both cases test gives output in same time.

Apart from avoid using xpath, what are other points to take care of to make project improve lot in case of speedy execution.

  • The primary reason for using ID (or names) is not speed, which is questionable assertion, it is to make the tests robust to a changing application. – Martin Spamer Oct 16 '18 at 19:59
2

This may not be a full answer to your question but I think it fits to the topic:

I was wondering about the "id is faster than xpath" and start searching. This SO-Question/Answer gives an answer which sounds quite logical.

But then I found these two Blogs from Elemental Selenium:

which shows that XPATH is faster than CSS. In the second one the author describes that he used the benchmark lib from ruby for his measurements.

For benchmarking I used the library that's available in Ruby's standard lib called 'benchmark'

But as you see the numbers of his comparion you see they don't diverge so much, so I think it's better to use CSS because of the compatibility as not all browsers implementing XPATH the same way. (And yes that's not part of your question)

2

I see two possible intepretations of your question here. The first is "How can I improve the speed of how elements are found on a page?". Another is "How can I improve execution speed of my suite of tests?".

The first question has some answers already. You've found that xpath vs id doesn't provide much speedup, so you're almost at the end of the road there.

The second question has more answers. Remember that if you're using WebDriver for end-to-end test automation, there's many, many things that affect your tests, such as

  • Browser rendering of HTML
  • Browser JS compilation and execution
  • Internet connection speed
  • CSS Styling
  • DOM Generation and updating
  • Screen resolution
  • Application load time
  • Browser navigation
  • HTML structure
  • Server-side application logic
  • Client-side application logic

These may all affect how stable your tests are, and in turn how well they run.

To get better run-time performance, I'd suggest the following:

  • Make sure your network connections/Internet connections are reliable and as fast as possible. Latency causes your apps to run more slowly which in turn causes tests to run more slowly.
  • Use physical or virtual machines with good hardware specs. Running on low-powered machines (in terms of RAM or CPU) may cause flakiness in your web app which in turn causes flaky tests.
  • Run your tests in parallel as much as possible. Divide large suites into smaller suites that can be run independently at the same time.
  • Avoid writing low-value tests. End-to-end tests are inherently long-running tests, and so tests that don't contribute much to understanding your application waste run-time.
  • Write deterministic tests. Tests that don't require a lot of overhead in terms of setup and teardown run quicker and more reliably.

In my experience these are effective ways to get your test run-time down.

1

A typical way to measure the length of a short operation is to measure the total time required to perform the operation many times, divided by the number of times you performed it. How many times? It depends on the operation; I usually start with a small number and keep doubling it, or multiplying by ten, until the answer has as much precision as I need.

There are innumerable ways to make software faster but you did not provide enough details to recommend anything specific.

  • What are the big and minute points I need to look at which are acting as party pooper in the whole automation projects? Xpath is one of those, what else? – paul Nov 30 '15 at 14:29
  • 1
    Sorry, that's like asking "How do I make software better?" You did not provide enough detail to answer the question. Please write a new question that provides specific details about what you are trying to do. – user246 Nov 30 '15 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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