Sunday 18 September 2016

How to Open Browser in Incognito / InPrivate mode using Selenium / WebDriver

How to Open Chrome Browser in Incognito mode using Selenium / WebDriver ?

        We will use Chrome Drivers Capabilities & ChromeOptions to open Chrome browser in incognito mode. To be precise, we have to use argument --incognito  for ChromeOption as shown in below example-

How to Open Firefox Browser in Incognito / Private mode using Selenium / WebDriver ?

    We will use Firefox Profile  to open Firefox in private mode. To be precise, we will set browser.private.browsing.autostart in firefox profile preference.


How to Open Internet Explorer (IE) Browser in InPrivate mode using Selenium / WebDriver ?  

    We will use IE Driver Capabilities to open IE in InPrivate mode. To be precise we will use FORCE_CREATE_PROCESS capability along with IE_SWITCHES to which parameter would be -private



This is all for now.
Cheers!!
Share:

How to open a new tab in a browser using Selenium WebDriver?

TL;DR:This is a story. If a story does not fascinate you, jump to the solution.

Prologue:-
If you constantly monitor many forums for some reason like LinkedIn groups, Google groups, Stackoverflow for Selenium related queries, you will find a question that has been asked many times with the same answer. Yes, I’m talking about the below question -

How to open a new tab in a browser using Selenium WebDriver?

Or this might have been asked in different style like -

Open new tab instead of a new window using Selenium WebDriver


You will easily find an answer after quick Google search. Why this post? 
           Because I do not agree with the most accepted answer of this question. I am not saying that solution provided is wrong or it won't work, I am just saying that I disagree with the solution provided. What is the solution provided by the way -  Here starts our story.


Open a blank tab in a browser using Selenium WebDriver


And very obvious solution would be use of sendKeys 



           Now the above solution uses shortcut keys provided by the browser to open a new tab. Generally, all browsers use same keys to open a new tab. BUT shortcut keys are OS specific. Being said that solution provided is not platform agnostic. If you want to open the new tab on Macintosh / Mac OS, you have to send  COMMAND+‘t’  together so your code would be like - 


            So if think you have solved the problem straight away using sendKeys, think again. I mostly use windows OS and I estimate my effort based on the amount of time needed to make the code work on windows as selenium is platform agnostic but using such approaches we need to spend additional time on another platform. This is a lesson learned in a hard way. So if you still want to use send keys approach with both OS [which is mostly the case with web application] , your code would look like this-



            This is not very efficient code, every time you want to open a new tab you have to check OS and then you add the complexity of If else to open a new tab.

Solution:-   
            Why not use javascript? All major browsers support javascript. Use javascript to open a new tab in Selenium WebDriver. Simple & elegant solution.



Bonus:- Open URL in a new tab in Selenium WebDriver.

Sometimes you might need to open URL in a new tab which you evaluated after some operation in a browser. All you need is send a parameter to javascript as below.


This is all for now.
Cheers!!
Share:

Saturday 10 September 2016

How to uncheck proxy server settings in chrome browser using Selenium WebDriver

If you have read my past post, you might know that I follow a lot of forums to understand what type of issues are faced by the community. This helps me to broaden my knowledge. A couple of days ago, I stumbled upon this question on such forum on Facebook.


Question was-

How to uncheck proxy server settings in chrome browser using selenium Code ?” with Below image.




Proxy Server Setting for Browser
Proxy Server Setting for Browser


That was a really interesting question, thanks for this question ‎Roby Chauhan.


Defining problem statement:-

Uncheck proxy setting while invoking Chrome browser using Selenium WebDriver.



Understanding Problem Statement:-
I first tried to solve this question manually and realised once again that proxy setting that you applied in one browser are not just that browser specific but it OS specific.


That means if you set proxy in one browser it is applicable to all browser. If you set the wrong proxy in one browser you would not able to connect to the internet using any browser. Refer image below for more understanding. The image is taken from Chrome support group for education and help.


Order of Precedence for Chrome Policies:
Order of Precedence for Chrome Policies


So basically we are talking about this red box, where we doing some setting which we need to overcome while invoking chrome using Selenium WebDriver.


Solution:-
After a lot of search on Google, I found a solution somewhere on the internet, we need to use Capabilities & ChromeOptions of chrome. To be specific below option:-


options.addArguments("--no-proxy-server");


Please check working code snippet below:-



This is all for now.
Cheers!!

Share:

Thursday 8 September 2016

History Of Selenium WebDriver

I have assumed that you have already read my past blog entry, Introduction to Selenium WebDriver and here on the quest to find out technical answer of question - what selenium is?
Before getting to the answer, I want you to go though the below info-graphics of history of Selenium WebDriver. 


History of Selenium and Evolution of Selenium over time
History of Selenium



Now that you are aware of history, Can you answer what Selenium is?

Selenium is set of tools which includes :-
  • Selenium IDE
  • Selenium RC
  • WebDriver
  • Selenium Grid

So meaning of Selenium depends upon the context, citing the man himself - Simon Stewart here -

Unfortunately, the Selenium project uses a lot of jargon.

  • Selenium Core is the heart of the original Selenium implementation, and is a set of Javascript scripts that control the browser. This is sometimes referred to as "Selenium" and sometimes as "Core".

  • Selenium RC was the name given to the language bindings for Selenium Core, and is commonly, and confusingly, referred to as just "Selenium" or "RC". It has now been replaced by Selenium WebDriver, where RC's API is referred to as the "Selenium 1.x API"

  • Selenium WebDriver fits in the same niche as RC did, and has subsumed the original 1.x bindings. It refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just "WebDriver" or sometimes as Selenium 2. Doubtless, this will be contracted to "Selenium" over time.

The astute reader will have noticed that "Selenium" is used in a fairly general sense. Fortunately, context normally makes it clear which particular Selenium people are referring to.

For Reference : Selenium RC architecture

Selenium RC architecture
Selenium RC architecture

    On 29th July of 2016, Selenium Committee announced Selenium 3.0 beta  and from now onward Selenium is not going to support Selenium Remote Control[RC] API or Selenium 1.0 API. This means, once Selenium 3 is publicly released you can say Selenium is Selenium 3.0 which is enhanced version of WebDriver and you no longer need to know what Selenium core is or what RC is. You just need to know WebDriver implementation of Selenium.

This is all for now.
Cheers!!
PS:-
All images used in infographics are taken from Google. Selenium RC architecture diagram is taken from official Selenium website.

Information source for infographics :-
  1. Official Selenium Website
Share:

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!!
   
   
Share:

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!!
Share:
Copyrights held by Amol Chavan. Powered by Blogger.