Wednesday, January 17, 2018

Interview Question - How to run same test case multiple times

In this blog, We will see how to run same test case multiple times. We can run same test case multiple times with help of @Test attribute 'invocationCount'.

@Test(invocationCount=?):

This invocationCount determined how many times TestNG should run this particular test method.

Example:

@Test(invocationCount = 2)
public void repeatTest()
{
     System.out.println("Execute Test 2 times");
}

Output:

The repeatTest() method will run 2 times.

Execute Test 2 times
Execute Test 2 times

PASSED: repeatTest
PASSED: repeatTest

Now let's see how to use invocationCount in Selenium script with the example.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class RunSameTestMultipleTimes 
{
@Test(invocationCount = 2)
public void loadApplication()
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
System.out.println("Page Title is " +driver.getTitle());
Assert.assertEquals("Google",driver.getTitle());
driver.close();
driver.quit();
}
}

Output:

You will notice that Firefox browser will prompt out and close 2 times.

Page Title is Google
Page Title is Google

PASSED: loadApplication
PASSED: loadApplication

Thursday, January 11, 2018

Javascript in Selenium Web-driver

Hello All,

Welcome to Software Testing Made Life Easy blog. In this post, we will see how we can introduce Javascript in Selenium Webdriver.

What is Javascript?

Javascript is one of the programming languages of the Web and It is a lightweight programming language and most commonly used as a part of web pages.

All modern HTML pages are using JavaScript.

Use of Javascript in Selenium Webdriver:

We have used Java in our script and we have implemented almost all features but some features can’t be handled by Java. So we need scripting language which can control server side & client side scripting. That's why JavaScript comes into the picture.

Implement Javascript in Selenium Webdriver:

To implement Javascript in our selenium script, We don't need to write the separate code because we have a predefined interface available in package org.openqa.selenium.JavascriptExecutor.

Inside this, We have some predefined method called executeScript() - Whatever script you will pass as a 'String', those will be executed by JavascriptExecutor.

Example:

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class JavaScriptTestCase
{
public static void main(String[] args) throws InterruptedException
{
WebDriver driver=new FirefoxDriver();
System.out.println("Launching Browser");
driver.manage().window().maximize();
driver.get("https://software-testing-made-lifeeasy.blogspot.in");
((JavascriptExecutor)driver).executeScript("document.getElementById('s').value='Balaji'");
}
}

Tuesday, January 9, 2018

Interview Question - What are the difference between web app and mobile app?

Mobile App:

A Mobile App is an application developed essentially for a particular handset and it will be installed directly onto the device.


Web App:

Basically, Internet-enabled apps that are accessible via the mobile device’s Web browser.



Accessibility:

A mobile app is totally compatible with the device’s hardware and native features, such as the GPS, the accelerometer, the compass, the list of contacts, and so on.

On the other hand, Web app can access only a limited amount of the device’s native features.

Upgradability:

A web app is much more dynamic than a mobile app in terms of updating the content.

Efficiency:

Mobile apps are more expensive to develop. However, they are faster and more efficient. Users can access the app only via the app store.



Web apps may result in higher costs of maintenance across multiple platforms. Also, there is no specific authority to control the quality of these apps.

Reach:

A web app is accessible across platforms and can be easily shared among users, as well as search engines, it has considerably greater reach than a mobile app.

User Interface:

Both the mobile apps and the web apps look and work the same way with a very little difference (The choice and decision is up to you ðŸ˜Š) 

Feel free to share your valuable feedback.Thanks.

Wednesday, January 3, 2018

Challenges we faced in Selenium Automation Testing

I work on Selenium Automation Testing and one of the major challenging tasks which I faced was, After invoking the application URL on any browser, it was required to authenticate the window based pop-up as below. The first challenge was selenium doesn't handle windows based pop-ups.

The solution is AutoIt tool (Click here!)
I wrote code using AutoIt which can easily handle the window based pop-up to enter credentials.
About AutoIt tool:
AutoIt is a tool where we can capture window based objects and write a simple AutoIt script. Once we compile & Run the AutoIt script file, It will generate the .exe file and which can be invoked within our selenium automation scripts.
Now, all we need to do is call the .exe soon after invoking the application URL. Please refer the sample code below
driver.get("application URL");
Runtime.getRuntime().exec("path where the .exe file exists");
Now the actual problem was AutoIt code was not getting triggered after invoking the application URL - driver.get("application URL").
Please find the solution to the above problem:
Subsequent lines of code will not execute unless execution of driver.get("application URL") method is complete. We found out that driver.get("application URL") was not getting completed unless we complete the window based pop-up operation.
The only solution is to run both driver.get("application URL") method and AutoIT code in parallel. This can be achieved with help of Java multi-threading.
After invoking the application URL, We will be giving control to window based pop-up and due to parallel execution, AutoIt.exe code will trigger and enter the credentials in a window based pop-up and completes the operation. Due to this, driver.get("application URL") method will also gets completed.
Code:
driver.get("application URL");
AUTOIT startExe=new AUTOIT ();
Thread t1 =new Thread(startExe);
t1.start();
Finally, I solved the issue.
Feel free to share your valuable feedback.Thanks.

Tuesday, January 2, 2018

Basic SQL Interview Questions & Answers for Software Testers

1. What is the difference between Delete and Drop commands?

Delete Command:
  • Delete removes the data from the table and the structure of the table will be retained.
  • This is a DML command.
  • Rollback is possible.
Drop Command:
  • Drop permanently removes both the data as well as the structure of the table.
  • This is a DDL command.
  • Rollback is not possible.
2. What is the difference between Delete and Truncate commands?

Delete Command:
  • Delete command deletes only the rows from the table based on the condition given in the where clause and also it deletes all the rows from the table if no condition is specified.
  • It does not free the space containing the table.
Truncate Command:
  • Truncate command is used to delete all the rows from the table and free the space containing the table.
3. What is a primary key?

A primary key is a combination of fields which uniquely specify a row. Primary key values cannot be NULL.

4. What is a foreign key?

The relationship needs to be created between two tables by referencing foreign key with the primary key of another table.

5. What is Joins in SQL?

Joins are used to combines the results of two tables. It combines the data based on the relationship between tables.

6. What are the different types of joins in SQL?

Following are the most commonly used joins in SQL:
  1. Inner Join
  2. Right Join
  3. Left Join
  4. Full Join
  5. Left Outer Join
  6. Right Outer Join
7. What is Inner Join in SQL?

Inner join returns matching rows between the two tables.

8. What is the difference between BETWEEN and IN condition operators?

The BETWEEN operator is used to display the rows based on a range of values. 
Examples:
Select * from blogs where pageviews BETWEEN 10 AND 20;

The IN condition operator is used to check for values contained in a specific set of values.
Examples:
Select * from blogs where country IN ('Germany', 'France', 'UK');

9. Is it possible for a table to have more than one foreign key? 

Yes, A table can have many foreign keys and only one primary key.