Can anyone please help me with Approach to validate the Search Results in e-commerce website? Suppose I entered any keyword in the search bar and N number of records is displayed post clicking search button. Now if I need to validate all the items displayed in the search result what should be the approach? Do I need to reiterate all the items and then compare each string with Expected output?


What are you trying to "validate"? The HTML output, or the data structure itself? You mentioned Selenium, but usually driving a browser is the slowest way to test something. I'm a WordPress developer, so the best tool for my e-commerce sites is Codeception. In Codeception you could test this in at least two basic ways:

Acceptance Test - You could use Selenium webdriver, but I'd recommend PhantomJS, because it is a lot faster. This method would involve driving the browser [or the virtual browser], and confirming the site is doing what you expect it to do.

Unit Test - Assuming that you understand how the platform you're coding for works, at some point in the stack there is some kind of class that can return what you're looking for as a testable object. Usually unit testing is exponentially faster than acceptance testing, since you only test the absolute smallest thing you can think of.

These two approaches might be associated with Behavior Driven Development and Test Driven Development. BDD is often thought of as an "outside in" methodology, which lends itself to browser based acceptance tests. TDD is usually incremental and small, and unit focused. It's faster, but lacks context.

There isn't a right way. My experience is that browser based testing is easier to understand, because you already know how to use a browser. As you gain experience, you'll drive the screws down deeper, and API and unit testing will be the way to go.

  • Thanks John for your response. We already have Selenium Tool in place for automating e-commerce website. So I have to stick to this tool. I just want to understand any better approach to verify if the search results is relevant to the keyword searched. Jan 4 '18 at 17:13
  • 2
    Your second paragraph is pretty confusing--Selenium and PhantomJS aren't mutually exclusive. Selenium is a browser automation tool, PhantomJS is a headless browser. You can use both together.
    – c32hedge
    Jan 4 '18 at 17:52
  • In PHP [i.e. Codeception or WordPress stack.. common ecommerce] we would use Selenium and PhantomJS exclusively. Selenium to drive a HEADED full browser [i.e. Chrome], and PhantomJS to drive a headless JS browser. Phantom is a LOT faster. I recommend most cases that use Selenium start using Phantom, unless you're testing something specific to Alphabet products, like youtube. Otherwise, made your site fully compliant and forget about testing on FF, Chrome whatever. Actually, the main reason I use Selenium is to show a business client something flashing in the GUI, no other reason.
    – John Dee
    Jan 4 '18 at 23:51
  • c32hedge, thanks you're right. I was refering to Selenium WebDriver. Sorry for the confusion. There are several products called "Selenium" that are related, the IDE, RC, etc. One common stack for PHP is Selenium WebDriver with a full browser, the other common stack is PhantomJS with no seperate browser. But you're right, they aren't totally exclusive.
    – John Dee
    Jan 4 '18 at 23:56
  • Tushar, absolutely the way to test this is via a unit test, and not a browser based test. You're testing the DATA here right, not the presentation layer? For example, what if the answer is translated in the browser, or a modal pops up over the data? Test what's important, in this case the data response.
    – John Dee
    Jan 5 '18 at 0:07

I have some experience with e-commerce and search. At first, we also wanted to automate search results on GUI level, but after some analysis, we found out that it is not delivering information what we need. We had daily releases on PROD, our customer changed products frequently (nightly import), no point to test search results on the TEST-machine and not business friendly to maintain fake products on PROD. At the end, we built checks for indexing job.

  • Thanks allot for your response. Could you please elaborate further on the validation of indexing job? Jan 6 '18 at 2:02
  • Sorry, it is already some time ago. The lead developer wrote a unit test, but what exactly he used for validation, I do not remember.
    – kriscorbus
    Jan 6 '18 at 19:56

Compare UI search data(actual with selenium) with db data(expected through direct SQL queries) and verify the results based on these 2 data sets comparison.

Compare and verify on 2 level: 1).Records count 2). Content

It is more of an middle ground between full UI test or full unit test.


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.