Thursday 25 August 2016

How can I enhance/improve my selenium skills?

Two months ago, when it was just six months in automation using Selenium and then I had a question - how can I enhance/improve my selenium skills? In this post, I am trying answer this question. 

 

You might think, why do I think that I have eligibility to answer this question? OK, here is the story- it's been just eight months that I have started with Selenium and I got an amazing opportunity to explore all aspect of Selenium and related tools like Selenium WebDriver API for Web-App automation, Selenium Grid for test distribution, TestNG for controlling test flow, Extent Reporting for awesome test results, Appium for mobile automation, AutoIT & Sikuli for handling native OS control opened from browsers (Browse window for file upload) & bit of Maven for dependency management & testsuite invocation. I have even designed two automation frameworks for two different products.


    As I worked on whole set of tools in six months, I was exposed to very high learning curve in early phase and later I found out my learning curve is going stagnant so I have to make an effort to keep enhancing my skills. Below are the list of the things which I did and doing and benefited on my quest to enhance/improve selenium skills:-
  1. Follow Leaders

If you need to sharpen your any technical skills, you should try to write about it more often. This has helped me a lot. This is one of the reason why I post.   Basically writing any post needs research and you also need to articulate the thoughts in a way so that it make sense to others. If you learn something new today, write about it. Writing about any topic in Selenium, first,  you need to have an understanding of that topic and then you have to develop the ability to make it simpler for others. Writing helps us to recall our learning curve and that sort of thing stick with a mind for a very long time.

If you have time every  day and wanted to utilise your knowledge to help someone you can always turned up to Stackoverflow without hesitation.  What is stackoverflow?
“A language-independent collaboratively edited question and answer site for programmers.”
You can follow tags like Selenium, Selenium-WebDriver and testng, so that you will found related questions easily.

This is just like any other google group where user seek product related help. Lots of guys do answer to posted questions. If you want to know what kind of issues are others in community are running into, you can subscribe for summary email. One of the advantages to be active in such  community is finding different approaches for same issue which of course helps to build better perspective for automation.

This is Linkedin group for selenium related queries, it also does helps user with the same way that Google Group does. But this not official group of Selenium.

  1. Follow Leaders:-

Follow who are doing great in Selenium and their posts/answers can take you to next level. Few suggestion from me:


This is all for now.
Cheers!!
   
   

Monday 1 August 2016

Data Driven Testing And Negative Testing

As a QA, I know what is Data Driven Testing (DDT) and what is Negative Testing refers to from last 5 years. But before today, I had never realized that negative testing is a subset of data-driven testing. With this post, I will try to explain my understanding of data-driven testing & negative testing and why I think of negative testing as a subset of data-driven testing.

      As per Wikipedia, data-driven testing is a term used in the testing of computer software to describe testing done using a table of conditions directly as test inputs and verifiable outputs as well as the process where test environment settings and control are not hard-coded.

This sounds very hard to me, I will try to make it simple but not simpler for you.
“Testing is driven by data.” But what does that exactly means?
Example :- Addition Operation in Calculator

Addition Example of Data-Driven Testing
Addition Example of Data-Driven Testing

So as you can see in above example, Output of operation changes as per the input passed. That means results are driven by data you supply in software.
All this seems very inconvenient to you? Or that example is too vague?
One may ask why we need to pass 3 different set of data even one set of data is enough to show that addition is working. But what if it's working coincidently, only for values passed in that test.[Remember this : QA should never make an assumption.]  I will try to answer your dilemma with another example.

Example :- Multiplication Operation in Calculator

Multiplication Example of Data-Driven Testing
Multiplication Example of Data-Driven Testing

Now, do you think that using a single set of data is OK to test this functionality?
Certainly NOT.
There are applications which have to be tested against multiple sets of data to cover all the functionality of that software. In above example, testing of multiplication needed to be tested against zero, when you use 0 (zero) as a first input and 0 (zero) as a second input. This is part of coverage of multiplication of module functionality testing, without such data-driven test we cannot say that test coverage of module is 100%. [For simplicity we have considered addition & multiplication of a whole number and for single digit.]

To summarise, what I am saying is there would be numerous applications in real life where you need to test the functionality for the different set of data. And for each set of data output would be different.
    This is pretty true for application in capital markets, by changing value of the flag in an application the result would be different. Such type of application MUST be tested with all required set of input data. Consider you have eliminated only one set of data while testing and developer had not taken care of that scenario. Your company may lose millions of dollar due to such mistake and it may cost you a job.  

I hope, by now you have understood what data-driven testing is and why it’s important. Now let’s move to next part and that is Negative Testing.


As per Wikipedia, Negative Testing is a test designed to determine the response of the system outside of normal parameters. It is designed to determine if the system performs error handling with unexpected input.
This concept is very simple to understand. Let’s take an example of Login into the Bank application.

         So as a tester my positive test would be “I should be able to login to into the application with valid credentials”. This is how we start the execution of our end-to-end test cases. But what would happen if we did not execute test for invalid credentials. Do you think your all green end-to-end pass result will make any significance if anyone able to login to bank application even if he does not have credentials?  So what should we do as a tester? We should execute test for error handling[Wrong Password - application should display proper error  message to user] and for unexpected input[Blank username, spacial character in fields where those are not allowed - application should display proper error message.]

Above example is self-explanatory. Now let’s move to last part, Why Negative testing is a part of data driven testing. I will formulate the table which encompasses what I have explained in above examples.



Negative Testing Example
Negative Testing Example



I have not covered all the negative scenarios of Login here, but this clears the idea.

Remember this:- Negative testing is a subset of Data-Driven testing that means all negative tests are basically data driven tests which are written to check error handling of the system with unexpected input but all data-driven tests are not Negative testing.



This is all for now.
Cheers!!

Saturday 16 July 2016

Highlight Element in Selenium WebDriver

  I missed highlighting object feature of QTP when I used to debug my selenium API call on webelement. Number of times I wondered, why didn't by default any method is provided to perform highlight action. But I no longer wish for same as I have found work around.  

      Remember this - ‘JavaScript comes in handy to perform any fancy tasks on DOM.’

Logic to perform highlight WebElement in Selenium WebDriver:-


       To create highlight effect, as in QTP, we don't just need to highlight the element but also have to de-emphasize/play down the same element. Highlighting element once is not enough, as the operation would be fast and we may don't realise highlighting effect. Better we break down logic as in below steps:-
  1. Highlight element using javascript.
  2. Play-down same element using javascript.
  3. Perform above two actions in a loop for significant time.

Below code demonstrate use of JavascriptExecutor to perform highlight element in Selenium WebDriver.

As you can see in above code, method highlightElement accepts WebElement as parameter and perform highlight operations for 5 seconds [i<5].

This is all for now.
Cheers!!

Sunday 10 July 2016

Object Repository in Selenium/Webdriver

From last 6 month or so, I am happily playing with Selenium API. Earlier, I invested more than 3 years in QTP/UFT. After spending that much of time in QTP, it’s very obvious that moving to selenium is not easy game and you cannot help yourself but compare this two things. You missed a lot of things from QTP when you move to Selenium, I can enlist few of those as follows:-
  1. Actions
  2. Datatables
  3. Checkpoints
  4. Smart Identifications
  5. Recovery scenarios
  6. Readily available test execution results and
  7. Object Repository and OR Manager

This is not the complete list but still this are the majors which I have missed.
“Journey becomes easy and better when you have good companion.” I went through many forums to find out good companion for learning selenium and finally settled on a book Selenium Testing Tools Cookbook by Unmesh Gundecha. When I started to learn selenium, I thought of  creating Object Repository in selenium. The book by Unmesh, itself was presented with recipe of implementation of Object Repository [OR]. I have done some changes in implementation as per need which we will discuss in this post.  

What is Object Repository (OR) anyway?

Object Repository is a mechanism to store objects information from application under test for performing action on those objects in a test script, it acts as interface between Test script and application in order to identify the objects during the execution

Setting Up Object Repository for Selenium WebDriver

         We know that, QTP internally uses  XML to store object repository and someone already answered on stackoverflow  to show use of XML as object repository for Webdriver. Personally I prefer to use properties files as they are more readable than XML files. As you might aware that property file uses key-value pair format. You must decide the format for your properties file, I am using it in following way:-


[logical_name]=[locator_type]~[locator_value]

Where -
[logical_name]:Logical Name generally would be label of element.[As it displayed on the UI]
[locator_type]:Locator type must be one from the following-id, name, className,  linkText, partialLinkText, cssSelector, xpath, tagName.
[locator_value]:Locator value - Value of locator_type

Sample property file screenshot-
Sample Object Repository Selenium WebDriver
Sample Object Repository Selenium WebDriver

Fetching objects from the Object Repository:-

Now that we have created properties file (OR), we need to have mechanism in a place to fetch this objects in our test script. Let's design a class which will help us to achieve following objectives.:-

  1. Get WebElement as mentioned in our properties file.[method getElement()]
  2. Get Locator as mentioned in our properties file. [method getLocator()]

Using Object Repository in Selenium WebDriver script:-

Now let us try to automate the scenario of login to application which uses Login OR  [Login.properties file as shown in image], ObjectMap class.



Above script demonstrate login to wordpress. It uses getLocator method from the class ObjectMap. This is very straightforward example of OR, it does not uses Page Object Model or TestNG. If you notice, we have not used getElement method from the ObjectMap class and used one OR in a script like shared OR. May be in future, I will post related articles which will show use of OR as Local OR along with Page Object.

This is all for now.
Cheers!!

Tuesday 21 June 2016

Block Push Notification on Chrome in Selenium Webdriver


Many of you might already know that Chrome browser supports push notification  almost on all platforms from version 42  and many sites including Facebook and Google+ have already started delivering push notification for end users. So when it comes to automating such sites/apps first thing that you notice is browser asking permission to deliver push notification.


Block Push Notification on Chrome in Selenium Webdriver
Facebook asking for permission to show push notification

Problem Statement:-


As you can observe in above image that it would be impossible to perform immediate next action in browser after login as it’s been blacked-out. Chrome driver will wait for sometime (implicit wait) and then try to perform next step in browser, whatever it may be, it will fail and if you missed the step in execution which might cause failure of next step and result would be failed test/test suite.

Also push notification badges are not getting displayed as part of web document, so clicking on those button displayed is not possible through selenium.



Workaround:-

    Simple thing to do, is find body element of page [which exist for all the pages :-) ], and perform double click on it. But as mentioned, it would be just workaround.



Better Approach:-

    What you would have done if you have to do same thing again and again manually in this case? Consider testing ten different app and login scenarios for them. Any sane person would have searched for how to do the same manually.
Manually disable/block Push Notification in Chrome
Manually disable/block Push Notification in Chrome



Whatever you would have done manually, would it be possible to set this up while invoking chromedriver instance? Yes, This is where chromedriver Capabilities and ChromeOptions comes into the picture.
Almost for each user customizable setting there is ChromeOption available. You can check all options here. Now to prevent or block push notifications on Chrome we can use disable-notifications option.

This is all for now.
Cheers!!

Friday 17 June 2016

Selenium as a Windows Service

I have been playing with selenium grid from past few days and it becomes very tedious to me to setup the grid by firing commands in command prompt [I am mostly windows 7 user]. So I thought of running selenium grid as service and for that I have used NSSM - the Non-Sucking Service Manager.

To set up grid as service, obviously you need-
  1. Selenium-server-standalone-2.53.0.jar file (should work with other version but I have used this)

Selenium Grid Hub setup:-

    You need to have following files in folder ready to use before you start with this setup. My folder setup is like-

    To set up hub, we use following command in the command prompt.

java -jar selenium-server-standalone-2.53.0.jar -role hub


Check whether grid hub is up and running as shown in below image-


Now if you accidentally close your command prompt running, your hub will go down which used happen a lot to me as I was not very keen user of command prompt. By setting up this as service, anyone can get rid of orphan looking command prompt. Now close the command prompt and start with actaul setup of service.

Set up same selenium grid hub as service

NSSM



Detail use of every tab in NSSM is mentioned here. Verify that proper entries are made in the registry for same.


You can monitor SeleniumHub service running now in Services.


Here is your selenium grid hub working as service.


On Grid adding chrome-driver node -



java -jar selenium-server-standalone-2.53.0.jar -role node -hub http://192.168.0.174:4444/grid/register/ -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=1 -Dwebdriver.chrome.driver=C:\Grid\chromedriver.exe  

Execute above command in command prompt. You need to use your hub IP instead of 192.168.0.174 which is IP of my hub. 


Observe your selenium grid console now, you can see one chrome node is added over there.


Set up same chrome node as service:-

Close the previously running chrome node in command prompt. I’m passing below command as parameter while creating new service as ‘ChromeNode’ -
-jar selenium-server-standalone-2.53.0.jar -role node -hub http://192.168.0.174:4444/grid/register/ -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=1 -Dwebdriver.chrome.driver=C:\Grid\chromedriver.exe




 You need to use your hub IP instead of 192.168.0.174 which is IP of my hub. 




Verify that proper entries are made in the registry for same.


You can monitor ChromeNode service running now in Services.



Here is your whole selenium grid setup running as service.



This is all for now in selenium testing tools
Cheers!!
Copyrights held by Amol Chavan. Powered by Blogger.