Wednesday, October 7, 2015

Don't collapse all programming concepts into Selenium.

As a test developer in Selenium, you'll often time need to access things that are outside of the browsers control.  For example,

  • How do I open an excel file?
  • How do I write test results to file?
  • How do I run my test in Jenkins?
  • etc...
Beginners might search on Google, the term, "How do I open excel files in Selenium?", but what you'll find is your results might not match expectations or no results.

Let's try to understand the test ecosystem and architecture so you can better phrase your search queries next time you need to do something.

How it all fits together

In your Selenium WebDriver or RC test, you have these 3 main concepts.
  1. Your programming language - Your basic building block.
  2. Your test framework - The context of how your test runs and reports results, and execution of your test scripts/programs.
  3. Selenium Webdriver - The interface which your test scripts/programs use to access the browsers functions.  More specifically, accessing web elements within the browser.

Asking your question

Now when you try to ask the question, you'll want to go through these backwards.

Let's take the example, "How do I read test data from an Excel file?".

Going through the steps, we ask ourselves the following questions..
  1. Are we interacting with a web element or browser at this point? - No. We don't need to search for a Selenium/WebDriver solution for this problem.
  2. Are we trying to interact with the test environment? - Yes, we need to feed data
  3. Is there something I'm trying to do that's not part of Selenium/WebDriver or the test framework.  Possibly.  We may need to figure out how to open the file.
Given that 2 and 3 are yes.  You'll probably want to search along the lines of..
  • How do I feed Excel data into (insert your test framework here)
  • Reading Excel data into (insert your test framework here)
  • etc...
If that fails, you'll want to fall back to the language, and break the problem down into smaller pieces.  Here we'll want to read the Excel file into some sort of data structure, then feed that data structure into the test framework.
  • How do I open a Excel file in C#,Java, etc...
  • How can I read an Excel file in ...
  • How do I feed array data into (insert test framework here)

Conclusions

When you find yourself needing to find a solution.  Remember to figure out where in your test architecture you need the solution at and break down the problem.

1 comment:

Anonymous said...

A very basic mistake often made by beginners in test automation. Good that some one finally wrote a blog on it :)

I got the tip here from you and I will be writing couple of blogs on basics like these at www.testerlogic.com.

Do visit my blog in spare time and share your feedback on my work. Thanks.