Wednesday 5 July 2023

Different Ways of Store and Access Test Data

There are many ways to store and access test data for automation testing. It would be different scenario to scenario.
What will be best approach to store very large test data for automation?

1. Excel file in automation frameworks itself
2. JSON file in automation frameworks itself
3. Any external file
4. Static data in test case file
5. Store data in DB, create REST API using Springboot and access through that.

If you want to learn how each option works, you can contact me through Email or Linkedin.

How To Design Automation Frameworks with Minimum Automation Suite Run Time

When you are designing UI test automation framework for any micro services architecture based application, then how you will design, so that your automation suite run time will be minimum?

Obvious answer is run test cases in parallel. Apart from that, how you will design your automation framework, so test cases run in faster way?

As per me, I will create automation framework such way that we can leverage APIs (As it is micro service based architecture) in test cases. Write test case such way that all the preconditions will be done by API and then perform actual part of test case through UI.
Let's take an example, assume there is test case which required to create one record in system and then perform some operations on that record. Here, create record in system is precondition. So, I will do that thing through API first then login application through UI and perform actual operation and verification. It will take less time then run test case full in UI mode.

Here, you might have question that if create record from UI is not working then it will be miss. No. We can create small smoke suite in CI/CD which will be always triggered before full automation suite is triggered. If there is any failures in smoke suite then full automation suite will not trigger.
So, all basic functionality like Login, Logout, CRUD operations will be test through UI in smoke suite. Smote suite should be run in maximum 10 minutes. So, you don't required to do that from UI in all your test cases.

In that way, you can also maximum utilize your selenium grid architecture. AS, any browser session will open only for main test cases operation, precondition will be always done through API.

So, this way we can create hybrid automation framework (UI + APIs) and decrease automation suite run time.

Thursday 22 March 2018

General Selenium Automation Interview Questions

Selenium Automation is very popular trends in software testing industry. I have seen many articles in internet for interview questions. There is no any sure interview questions. It is all depends on interviewer.

I have prepared some interview questions for Selenium Automation only. If I am interviewer then i will ask that types of questions for sure.

I have added answers of question if I already added in my blog. If not then I will add later once I added in my blog.


1. Explain basic idea of selenium.
Ans : Selenium Basics


2. Explain me selenium automation project you worked. 



3. How to create hybrid framework using Data Driven and Keyword Driven framework?



4. How to use POM in selenium?
Ans : Page Object Model (POM) Framework in Selenium



5. Write java program for below definition.

If I enter number 5 then output should be as below.

5*5 - 4*4 + 3*3 - 2*2 + 1*1

If I enter 4 then

4*4 - 3*3 + 2*2 - 1*1

Ans : Java Program For Number Series

6. Write java program for below definition.

If I enter String 'aabbccddefgh' the output should be as below.

Output = 2a2b2c2d1e1f1g1h

Ans : Java Program For String Example

7. Explain difference between Implicit Wait and Explicit Wait.
Ans : Implicit Wait Vs. Explicit Wait Vs. Fluent Wait

8. How many element locators is there in selenium.
Ans : Different Locators in Selenium

9. Write Xpath for select element highlighted span tag in below HTML code.

<div>
 <span>Test</span>
  <span>Test1<span>
</div>
<span>ABC</span>
<div>
 <span>Test</span>
  <span>Test2<span>
</div>
<span>ABC</span>
<div>
 <span>Test</span>
  <span>Test3<span>
</div>
<span>ABC</span>
<div>
 <span>Test</span>
  <span>Test4<span>
</div>
<span>ABC</span>

Ans : 
Xpath = "//div[span/span[text() = 'Test3']]/following::span[text() = 'ABC']" 

10. How to maximize chrome browser directly when you initiate Webdriver instance. It should be open in maximize mode.
Ans : 
You can open chrome browser directly using capabilities when initiate webdriver instance. Please go to below link for how to use capabilities.
How to Set Capabilities and Proxy Setting for Webdriver

11. How to initiate Firefox browser for Firefox version grater than 48.
Ans : 
You have to use 'GeckoDriver' for Firefox version grater than 48. It means you have to set System property same as chrome browser with GeckoDriver.

System.setProperty("webdriver.gecko.driver", "Path of Gecko Driver");
WebDriver driver = new FirefoxDriver();


12. What is Maven in selenium?

13. Did you ever integrate Jenkins with selenium? If yes then explain how to integrate.

14. How many ways you can generate test result report?
Ans : There is many ways to generate test result report in selenium. Below is different ways to generate result report.

  • TestNG report (Auto generate when you use TestNG)
  • JUnit Report
  • Ant report
  • Excel report (You have to write code for this)
  • CSV report (You have to write code for this)
  • HTML Report using Extent report) - Go to this link Extent Report for Extent Report.

15. How to Handle browser based Popup in selenium?
Ans : How to Handle PopUp in Selenium

16. How to Handle Windows in selenium?
Ans : How to Handle Windows in Selenium

17. How to Handle Windows based Popup in selenium?
Ans : Handle Windows Based Popup

18. How to do SQL database connection in selenium?

Ans : How to Do Database Connection in Selenium

19. How to handle below scenario without using Implicit and Explicit wait. You can use Thread.sleep() function.

Scenario : I have one element on page and every time it will take different time to load on page. some time 1 sec, some time 5 sec and some time 8 sec. I want to click on that element. Maximum time you have to wait for that element is 10 sec. If element do not appear after 10 sec than throw exception otherwise click on that element.

Ans : How Handle Wait Without Using Explicit and Implicit Wait in Selenium

20. How to Highlight Element when you perform click on that element.
Ans : How to Highlight Element in Selenium


Please add comment if you have any questions.


How Handle Wait Without Using Explicit and Implicit Wait in Selenium

Suppose you have one element on page and every time it will take different time to load on page. some time 1 sec, some time 5 sec and some time 8 sec. I want to click on that element.
Maximum time you have to wait for that element is 10 sec. If element do not appear after 10 sec than throw exception otherwise click on that element.

We need to use Thread.Sleep() function for this scenarios.

I have created below function for handle this scenario.

    public boolean mWaitAndClick(WebDriver driver, WebElement vElement) throws Exception
    {
     boolean bWaitAndClick = true;
        int MAXIMUM_WAIT_TIME = 10;  // this is seconds               
        int counter;
        
        try
        {
   vElement.click();
 }
        catch (Exception E) 
        {         
   for(counter=1; counter<=MAXIMUM_WAIT_TIME; counter++)
   {
    try
          {
     vElement.click();
     
     bWaitAndClick = true;     
     
     break;
          }
          catch(Exception e)
          {
           Thread.sleep(1000);
          }
   }
   
   if(counter>10)
   {
    bWaitAndClick = false;    
    throw new Exception("Element not found");    
   }
   
 }
        
        return bWaitAndClick;        
    }





Java Program For Number Series

If I enter number 5 then output should be as below.

Output = 5*5 - 4*4 + 3*3 - 2*2 + 1*1

If I enter 4 then

Output = 4*4 - 3*3 + 2*2 - 1*1

Below is code.

First Method : 

public class JavaExampleSeries 
{
 
 public static void main(String[] args)
 {
  int number = 5;
  long output = 0;
  int counter = 1;  
  
  if(number%2==0)
  {
   for(int i=number; i>=1; i--)
   {
    if(counter%2==0)
    {
     output = output - i*i;
    }
    else
    {
     output = output + i*i;
    }
    counter++;
   }
  }
  else
  {
   for(int i=number; i>1; i--)
   {
    if(counter%2==0)
    {
     output = output - i*i;
    }
    else
    {
     output = output + i*i;
    }
    counter++;
   }
   output = output+1;
  }
  
  System.out.println("Output is : " + output);
 }
 
}

Second Method :


public class JavaExampleSeries 
{
 
 public static void main(String[] args)
 {
  int number = 5;
  long output = 0;         
  int iterations = number/2;
  
  for(int i=1; i<=iterations; i++)
  {
   output = output + ((number*number)-((number-1)*(number-1)));
   
   number = number-2;   
  }
  
  if(number%2>0)
  {
   output = output+1;
  }
    
  System.out.println("Output is : " + output);  
 } 
}




Java Program For String Example

If I enter String 'aabbccddefgh' the output should be as below.

Output = 2a2b2c2d1e1f1g1h


public class JavaExampleString1 
{

 public static void main(String[] args)
 {
  String temp = "aabbccddefhg";
  String output = "";
    
  System.out.println(temp.length());
  System.out.println("Input String : " + temp);
  int vCounter = 1;
  for(int i=0; i<temp.length(); i++)
  {
   if(i<(temp.length()-1))
   {
    if(temp.charAt(i) == temp.charAt(i+1))
    {
     vCounter++;
    }
    else
    {    
     output = output + Integer.toString(vCounter) + temp.charAt(i);
     //System.out.println(output);
     vCounter = 1;
    }
   }
   else
   {
    output = output + Integer.toString(vCounter) + temp.charAt(i);
   }
      
  }
  
  System.out.println("Output String : " + output);

 }

}

Tuesday 20 March 2018

How to Read Configuration File in Selenium C#

When we are working on automation framework then we have to follow such strategy so we can avoid hard code value as much as we can.

There are many parameters in every framework we can be changed frequently for running test case on different environment as well as with different configuration. So, we can not use hard code value for such parameters. We have to use configuration file for this scenario.

In that file, we can store all the parameters which are used in framework like browser name, browser type, application URL etc. in Key-Value manner.

First of all you have to 'System.Configuration' assembly reference to access configuration settings, using ConfigurationManager.

You can add that assembly reference from right click in References then go to Assembles section and add it.



There are many methods for read configuration file.

First Method:

Suppose we have below 'app.config' file in project. We have only one section 'appSettings' and very simple app.config file.


<?xml version="1.0" encoding="utf-8" ?>  
<configuration>  
  <startup>  
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />  
  </startup>  
  <appSettings>  
    <add key="BrowserName" value="Chrome"/>  
    <add key="BrowserType" value="local"/>
    <add key="URL" value="www.google.com"/>  
  </appSettings>  
</configuration>  

Now, you need to create one function for reading parameters in 'appSettings' section. I have created below function for that and I have used 'ConfigurationManager' for reading value.


public static void ReadConfigurationFile()  
    {  
        String browserName = ConfigurationManager.AppSettings["BrowserName"];  
        String browserType = ConfigurationManager.AppSettings["BrowserType"];
 String URL = ConfigurationManager.AppSettings["URL"];  
          
    }

You can use above function for reading values from configuration file.

Second Method:

Suppose we have below 'app.config' file in project. We have only one section 'ApplicationSettings' but we have defined that section in 'configSections'.


<?xml version="1.0" encoding="utf-8" ?>  
<configuration>  
   <configSections>  
    <section name="ApplicationSettings" type="System.Configuration.NameValueSectionHandler"/>      
  </configSections>  
    
  <ApplicationSettings>  
    <add key="ApplicationName" value="First Project"/>  
    <add key="Browser" value="Chrome"/>  
    <add key="SecretKey" value="XXXXX"/>  
  </ApplicationSettings>  
  <startup>  
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />  
  </startup>    
</configuration> 

In this method, I have used GetSection() function for read values from sections.
I have created below function for reading value.


public static void ReadConfigurationUsingSection()  
    {  
        var applicationSettings = ConfigurationManager.GetSection("ApplicationSettings") as NameValueCollection;  
        if (applicationSettings.Count == 0)  
        {  
                Console.WriteLine("Application Settings are not defined. Pelase defined first.");  
        }  
        else  
        {  
            foreach (var key in applicationSettings.AllKeys)  
            {  
                Console.WriteLine(key + " = " + applicationSettings[key]);  
            }   
        } 

 String ApplicationName = applicationSettings["ApplicationName"];
 String Browser = applicationSettings["Browser"];
 String SecretKey = applicationSettings["SecretKey"]; 
    } 

In above function, we read all sections values in one variable using GetSection() function and then we read value one by one using 'Key'.

Third Method:

Suppose we have below 'app.config' file in project. We have one main section 'BlogGroup'. There is sub section 'PostSetting' in 'BlogGroup' section.


<?xml version="1.0" encoding="utf-8"?>  
<configuration>  
  <configSections>     
    <sectionGroup name="BlogGroup">  
      <section name="PostSetting" type="System.Configuration.NameValueSectionHandler"/>  
    </sectionGroup>      
  </configSections>  
  
  <BlogGroup>  
    <PostSetting>  
      <add key="PostName" value="Getting Started With Config Section in .Net"/>  
      <add key="Category" value="C#"></add>  
      <add key="Author" value="Sameer"></add>  
      <add key="PostedDate" value="20 March 2018"></add>  
    </PostSetting>  
  </BlogGroup>          
    
  <startup>  
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>  
  </startup>  
</configuration>   


In this method, I have used GetSection() function for read values from sections.
I have created below function for reading value.


public static void GetConfigurationUsingSectionGroup()  
{  
    var PostSetting = ConfigurationManager.GetSection("BlogGroup/PostSetting") as NameValueCollection;  
    if (PostSetting.Count == 0)  
    {  
        Console.WriteLine("Post Settings are not defined. Please define first.");  
    }  
    else  
    {  
        foreach (var key in PostSetting.AllKeys)  
        {  
            Console.WriteLine(key + " = " + PostSetting[key]);  
        }  
    }
 String PostName = PostSetting["PostName"];
 String Category = PostSetting["Category"];
 String Author = PostSetting["Author"];
 String PostedDate = PostSetting["PostedDate"];
 
}  

In above function, we read all sub sections values in one variable using GetSection() function and then we read value one by one using 'Key'.
Please add comment if you have any question.

Popular