Wednesday, September 27, 2017

Gherkin Keywords : Keywords used in Gherkin language (For Cucumber)

Keywords in Gherkin Language majorly includes: Feature, Background, Scenario, Given, When, Then, And, But, *

It's not necessary to write just automated tests using Gherkin. Gherkin can also be used to create project documentation in a structured manner. This structured format gives us the ability to automate them easily.

Sample .feature file:

Feature: Test Login Functionality for Amazon.com
Scenario: Login using valid username and password.
Given User is on Amazon.com
When User navigates to Login window.
And User enters valid usename and password combination
Then User should be able to Login successfully on Amazon.com website successfully.

Once we have installed Cucumber plugin in Eclipse and start writing our feature files in Cucumber editor, we notice that few words get colored. These words are the keywords namely,
  • Feature
  • Background
  • Scenario
  • Given
  • When
  • Then
  • And
  • But
  • *

Let's discuss these keywords in detail:

1. Feature: Feature keyword is the very first word in every feature file. It indicates what feature is being referred to in entire feature file. 

For Example: 
Feature: Test Login Functionality for Amazon.com

2. Background: Background keyword is used to define all common steps to be executed for every scenario. It helps us reduce redundancy of common steps for all scenarios. Background keyword can be used in Gherkin as in example below:

For Example: 
Feature: Test Login Functionality for Amazon.com
Background: Given User is on Amazon.com
And User navigates to Login window.

Scenario: Login using valid username and password.
When User enters valid username and password combination
Then User should be able to Login on Amazon.com website successfully.

Scenario: Login using Invalid username and password.
When User enters Invalid username and password combination
Then User should be not able to Login on Amazon.com website.

3. Scenario: Scenarios are various scenarios that can exist against above feature. 
For Example: Login using Valid credentials, Login using Invalid credentials, Login using blank/null credentials etc.

For Example: 
Feature: Test Login Functionality for Amazon.com
Scenario: Login using valid username and password.
When User navigates to Login window.
And User enters valid username and password combination
Then User should be able to Login successfully on Amazon.com website successfully.

Each scenario can be broken down to Precondition (using Given keyword), Test step (using When keyword), Verification (using Then keyword)

4. Given Keyword: It is used to set the precondition to the test Scenario.

For Example:
Scenario: Login using valid username and password.
Given User is on Amazon.com

5. When Keyword: It is used to set the test steps to the test Scenario.

For Example:
Scenario: Login using valid username and password.
Given User is on Amazon.com
When User navigates to Login window.

6. Then Keyword: It is used to set the verification to the test Scenario.

For Example:
Scenario: Login using valid username and password.
Given User is on Amazon.com
When User navigates to Login window.
And User enters valid usename and password combination
Then User should be able to Login successfully on Amazon.com website successfully.

7. And Keyword: It is used to Add conditions to the test steps.

8. But Keyword: It is used to Add Negative conditions to the test steps.

For Example:
Scenario: Login using valid username and password.
Given User is on Amazon.com
When User navigates to Login window.
And User enters username and password combination
But Credentials are wrong
Then User should be not able to on Amazon.com website.

9. * Keyword: * keyword holds the veto power and can be replaced with any of the keywords. Cucumber care about what code it needs to execute for each step irrespective of the keyword used. For example below mentioned example would execute perfectly fine as long as the code is glued to every step:

For Example:
Scenario: Login using valid username and password.
* User is on Amazon.com
* User navigates to Login window.
* User enters usename and password combination
* Credentials are wrong
* User should be not able to on Amazon.com website.

That's all about the keywords used in Gherkin (for Cucumber). Happy Testing!
Read More »

Tuesday, September 26, 2017

What all Cucumber Jars do I need to set up Cucumber in Eclipse?

In order to write and execute tests in Cucumber we need to add some Cucumber jars listed below (Similar to adding jar files for Selenium):
  • cucumber-core
  • cucumber-java
  • cucumber-junit
  • cucumber-jvm-deps
  • cucumber-reporting
  • gherkin
  • junit
  • mockito-all
  • cobertura

How to Download these jar files?

1. Open URL: https://search.maven.org/
2. Enter Jar Name for example: "cucumber-core" in Search bar


3. Hit Search
4. Click on jar download link as shown in screenshot below:


Repeat Steps 1-4 for all Cucumber jars listed above. Once all Cucumber jars are downloaded you can easily configure build path and add these external Cucumber jars to your Cucumber Test Project

Also, it's very important to download Cucumber jars from correct group id. You may get lots of Cucumber jars with same name so please match group id from table below to ensure that correct jar file is being downloaded. Happy Testing!

Read More »

How to add Cucumber plugin to Eclipse?

Here are the steps to add Cucumber plugin to eclipse easily and hassle free.
Prerequisites: Java & Eclipse should be installed with proper environment variables configuration.

1. Open Eclipse
2. Click on Help in Menu bar
3. Select Option Install new software

4. Enter "http://cucumber.github.com/cucumber-eclipse/update-site" in "Work with" field (Point 1 in Screenshot below)

5. Select checkbox (Point 2 in Screenshot above)
6. Click Next/Finish/OK depending on eclipse version(Point 3 in Screenshot above)

And It's Done. Happy Testing!
Read More »

What is Gherkin (for Cucumber)?

Gherkin is an English like language to express tests without any ambiguity. It consists of a set of
keywords used in a feature file to describe various components listed in it. Nothing more, that's it.

 It is a language easy to understand and write by all, thus making one able to understand and express application behavior concretely with solid requirements. Team is able to build better scenarios around already set concrete list of scenarios.

The whole idea of Gherkin is to make tests more readable. Having the ability to write tests in English like language, Even people like stakeholders with non-technical background will be able to understand your tests. They would be able to come up with more scenarios and define clear expectations which is always good to have.

Sample feature file in Cucumber:

Feature: Login functionality for Gmail.com

Scenario: Verify that user is able to successfully login using valid username and password to Gmail
Given A user is on Gmail website
When User clicks on Sign in link
And User logs in using valid username and password
Then User is taken to My Account page

No need to worry about keywords like Feature, Scenario, Given, When, And, Then. We will discuss these keywords in future posts. Happy Testing!

Read More »

Monday, September 25, 2017

"User Operation is waiting for “Building Workspace” - Eclipse error resolution

Are you too facing same error while executing Cucumber tests using JUnit as in screenshot below:

In order to resolve, simply unselect Build automatically from Project tab in menu bar as in Screenshot below:


Error Resolved. Happy Testing :)


Read More »

Friday, September 8, 2017

Difference between Smoke and Sanity?

Smoke and Sanity are two most confusing statements, hard to understand for beginners in the field of Software Testing.

Smoke Testing is done to make sure that all critical functionalities end to end are functioning properly so that QA Team can further proceed with more vigorous tests developed in Test Suite. Smoke is basic check at initial builds of a product where QA Team needs to be decisive: Whether to accept the build for QA or reject it? As there is no point driving a wheel-less vehicle, there is no point testing any code with missing critical functionalities. For Example: If Homepage of a website is not opening at all, build should be rejected and sent back to Development team instead of wasting time and accepting such builds.

Sanity Testing is done to make sure that all major new functionalities and bug-fixes are working fine. Sanity is done mostly at later builds / enhancements when the product is almost stable. For example: If the design of a website is to be changed and QA finds out that previous design is still coming, there can be some code merge issues or the services might not have been restarted or it might be cached somewhere, the Sanity test failure will stop QA Team to proceed further as the functionality that was to be tested is not at all testable.

Smoke Testing is usually scripted, automated or documented in most of the organisations, where as Sanity isn't (for an incomplete product).

Once a Web application is live running on production server, Sanity tests can be automated to check health of website daily at regular intervals. For an e-commerce website, sanity test cases may include:
  • Sign In & Sign Out
  • Homepage Components
  • My Account
  • Product Search
  • Product filters
  • Category Mapping
  • Checkout (Both Guest & Logged In)
  • Thank you page
But, for websites having frequent changes on basic functionalities, Automating Sanity is not suggested as the cost of maintaining the test suite would be quite expensive.
Read More »

Thursday, August 31, 2017

Airtel/Wynk Automation Testing Interview Question with Solution. (Java)

Hello World!
 
Recently I appeared for an interview at Airtel Wynk office, Gurgaon for the role of Automation Test Engineer. Here is the Automation testing interview question with free solution:

Question: Suppose you have an Integer "4296"
Step 1: Find smallest digit in integer i.e. '2' in "4296"
Step 2: Subtract smallest digit from all digits of the integer i.e. "New Integer" becomes: (4-2)(2-2)(9-2)(6-2) = "2074"
Step3: Now, Add all digits of New integer and print the sum i.e. 2+0+7+4 = "13"

Here is the Solution:
Read More »

Java Program to Reverse a String / Integer

Hello World! Below program will reverse any String or Integer. Happy Coding!
Read More »

Thursday, August 3, 2017

eCommerce website: Components and Testing

eCommerce is rapidly increasing day by day worldwide. Electronic commerce includes selling/buying products online over the world wide web. A tester deployed in eCommerce domain needs to know these basic components and technologies involved in testing eCommerce web applications.

Basic components of an e-commerce website:

Homepage: It's basically the very 1st page of an eCommerce website having banners, links to various categories, popular products, login/logout, Promotions, widgets etc.

My Account page: This page appears for a logged in user only. It contains saved addresses, saved bank card details, previous orders etc.

Search Page: This page contains the result set after a user enters a search string and searches for a particular product.

Product Page: This page contains the product and it's description along with product specifications like price, attributes like size, color etc.

Read More »

Sunday, July 30, 2017

Locators in Selenium

In simple words, Locators are similar to tracking the location of your Ola/Uber Cab on road. 

Once a web page loads on your browser there are several elements on the webpage for user to perform action on. There can be Input boxes such as username/password, Submit buttons, Dropdown lists, Texts, Radio buttons etc.

In order to perform action on any element on a webpage, selenium webdriver needs to know the location of the webelement. There are 8 distinct locators that are used to access webelements via Selenium webdriver:

1. Id | example: WebElement We = driver.findElement(By.id("username"));

2. Name | example: WebElement We = driver.findElement(By.name("submit"));

3. Linktext | example: WebElement We = driver.findElement(By.linkText("link Text"));

4. Partial Linktext | example: WebElement We = driver.findElement(By.PartialLinkText("link Text"));

5. Tag Name | example: Select se = new Select(driver.findElement(By.tagName("menu"))); select.selectByVisibleText("Jan");

6. Class Name | example: WebElement We=driver.findElement(By.className(“test”));

7. CSS | example: WebElement We = driver.findElements(By.cssSelector("input[id=password']"));

8. Xpath 
Read More »