September 1, 2016

Synchronization Techniques

Why are waits required in selenium?

In web automation waits are required as certain elements get loaded on the page, so after triggering an event a page may get loaded successfully but some of its element may still not get loaded. This causes elementNotFound exception.

In such cases we will be using Thread.sleep() i.e. a static wait that will halt the test execution for some specified time and then perform the next step. As Thread.sleep() will wait for the specified time no matter if the elements gets visible before the specified amount of time. So, using the Thread.sleep() method is never advisable for UI automation.

To avoid this, selenium provides different types of waits , in most of the cases we will use Implicit, explicit waits and pageLoadTimeout.

Implicit Waits –

An implicit wait when used is set to the WebDriver instance and is applied to all the web elements. In implicit wait the webdriver polls the DOM to check the availability of the webElement and waits till the maximum time specified before throwing NoSuchElementException.

Syntax:
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(<interger to represent the time>, TimeUnit.<UNIT>);
 - where UNIT might be SECONDS, MINUTES, HOURS, DAYS etc.,
 - TimeUnit is available from java.util.concurrent Package.

Example:
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

In the above example the value 10 specified in implicit wait method is the maximum time in seconds till which webDriver will wait before throwing NoSuchElementException while locating a webElement.

Explicit Waits –

Unlike implicit waits (which is applied on WebDriver instance without any condition), the explicit waits are applied to each and every webElement. In explicit wait certain conditions are defined for which the webDriver instance waits before locating webElements or performing actions on them. Some of the most common conditions specified in explicit waits are-
visibilityOfElementLocated, elementToBeClickable, presenceOfElementLocated etc.

Syntax:
WebDriverWait wait = new WebDriverWait(driver, <Time is Seocnds>);
wait.until(ExpectedConditions.<condition>(ElementLocator));

Example:
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(ElementLocator));

Here the webDriver instance will wait until the condition specified is met i.e. the visibility Of Element located by the Locator with the maximum wait time of 30 seconds after which if the condition is still not met than it will throw NoSuchElementException exception.


FluentWait Command :

Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Furthermore, the user may configure the wait to ignore specific types of exceptions whilst waiting, such asNoSuchElementExceptions when searching for an element on the page.

 Wait wait = new FluentWait(driver)
    .withTimeout(30, SECONDS)
    .pollingEvery(5, SECONDS)
     .ignoring(NoSuchElementException.class); 

PageLoadTimeout Command:

Sets the amount of time to wait for a page load to complete before throwing an error. If the timeout is negative, page loads can be indefinite.
driver.manage().timeouts().pageLoadTimeout(100, SECONDS);

SetScriptTimeout Command :

Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error. If the timeout is negative, then the script will be allowed to run indefinitely.
driver.manage().timeouts().setScriptTimeout(100,SECONDS);

August 19, 2016

Selenium Web Driver

Selenium WebDriver is an interface and it is a web automation framework that allows you to execute your tests against different browsers.
We've the following browser support
  • Firefox
  • Internet Explorer
  • Safari
  • Google Chrome
  • Opera Browser
  • HtmlUntilDriver (No User Interface)
Using WebDriver we develop the test cases using various programming languages.
Following programming languages are supported by WebDriver
  • Java
  • .Net 
  • PHP
  • Python
  • Perl
  • Ruby
We've several methods in Selenium WebDriver, few of them are listed below
  1. get()
  2. getCurrentUrl();
  3. getTitle()
  4. findElements()
  5. findElement()
  6. getPageSource()
  7. close()
  8. quit()
  9. getWindowHandles()
  10. getWindowHandle()
  11. manage()
  12. navigate()
Let’s look into the detail for each of the above methods.
Method Name: - get()
Syntax: get(url)
Purpose: It will load a new web page in the current browser window. This is done using an http get operation, and the method will block until the load is complete.
Parameters: URL - The URL to load and it should be a fully qualified URL
Example:
@Test
Public void testGetMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
}
Method Name: getCurrentUrl()
Syntax: getCurrentUrl()
Purpose: Gets a string representing the current URL that the browser is opened.
Returns: The URL of the page currently loaded in the browser
Example:
@Test
Public void testGetCurrentURLMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
String currentURL = driver. getCurrentUrl();
System.out.println(currentURL);
}
Method Name: getTitle()
Syntax: getTitle();
Purpose: Gets the title of the current web page.
Returns: The title of the current page, with leading and trailing white space stripped, or null if one is not already set
Example:
@Test
Public void testGetTitleMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
String pageTitle = driver. getTitle ();
System.out.println(pageTitle);
}
Method Name: findElements()
Syntax: findElements(By byLocator);
Purpose: Find all elements within the current page using the given criteria.
Parameters: By - The locating technique (Like id, className, xPath,cssSelector, linkText etc.,)
Returns: A list of all WebElements, or an empty list if nothing matches
Example:
@Test
Public void testFindElementsMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
List<WebElement> listElements = driver. findElements(By byLocator);
}
Method Name: findElement ()
Syntax: WebElement findElement(By by);
Purpose: Find the first WebElement using the given criteria.
Parameters: By - The locating technique (Like id, className, xPath,cssSelector, linkText etc.,)
Returns: The first matching element on the current page
Throws: NoSuchElementException - it will return exception if no matching elements are found
Example:
@Test
Public void testFindElementMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
WebElement element = driver. findElement();
}
Method Name: getPageSource()
Syntax: getPageSource();
Purpose: Get the source of the currently loaded page. If the page has been modified after loading (for example, by JavaScript) there is no guarantee that the returned text is that of the modified page.
Returns: The source of the current page
Example:
@Test
Public void testGetPageSourceMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
String pageSource = driver. getPageSource ();
System.out.println(pageSource);
}
Method Name: close()
Syntax: void close();
Purpose: Close the current window, if there are multiple windows, it will close the current window which is active and quits the browser if it's the last window opened currently.
Example:
@Test
Public void testDriverCloseMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
driver. close();
}
Method Name: quit()
Syntax: void quit();
Purpose: Quits this driver instance, closing every associated window which is opened.
Example:
@Test
Public void testDriverQuitMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
driver. quit();
}
Method Name: getWindowHandles()
Syntax: Set getWindowHandles();
Purpose: Return a set of window handles which can be used to iterate over all the open windows of this Webdriver instance by passing them to switchTo().window() method
Returns: A set of window handles which can be used to iterate over all the open windows.
Example:
@Test
Public void testGetWindowHandlesMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
List<String> pageHandles = driver. getWindowHandles ();
For(String pageHandle: pageHandles)
System.out.println(pageHandle);
}
Method Name: getWindowHandle()
Syntax: String getWindowHandle();
Purpose: To get the current window handle, this is used to navigate back to the parent window
Returns: Return a string which represent the current window handle
Example:
@Test
Public void testGetWindowHandleMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
String pageHandle = driver. getWindowHandle();
System.out.println(pageHandle);
}
Method Name: switchTo
Syntax: driver.switchTo()
Purpose: To perform the next future commands on different frame, alert or window.
Returns: A Target Locator which can be used to switch or select a frame or window
Example:
@Test
Public void testSwitchToWindowMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
String currentWindowName = driver.getWindowHandle();
driver. switchTo ().window(<window name>/<window id>);
System.out.println(pageTitle);

// To close the current window
Driver.close();

//To switch to parent window
Driver.switchTo.window(currentWindowName);
}

@Test
Public void testSwitchToAlertMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
String currentWindowName = driver.getWindowHandle();
driver. switchTo ().alert();

//To Accept the alert
driver.accept();

//To dismiss the alert
driver. dismiss();

//To switch to parent window
Driver.switchTo.window(currentWindowName);
}

@Test
Public void testSwitchToFrameMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
String currentWindowName = driver.getWindowHandle();
driver. switchTo ().Frame(<FrameWebElement>/<Frame ID> / <Frame Name>);

//To switch to parent Frame
Driver.switchTo.defaultContent();}
Method Name: manage()
Syntax: driver.manage()
Purpose: To manage the driver (Maximize, minimize, implicitlyWait etc.)
Returns: Returns an instance of underlying implementation of Interface Options which could be EventFiringOptions / RemoteWebDriverOptions.
Example:
@Test
Public void testManageWindowMethod()
{
WebDriver driver=new FirefoxDriver();
driver.get(URL);
//To Maximize the window
driver. manage().window().maximize();

//To get Size of the window
Dimension d= driver. manage().window().getSize();

//To set Size of window
driver.manage().window().setSize(new Dimension(width, height));

//To set wait time to the window
driver.manage().timeouts().implicitlyWait(<integer value>, TimeUnit.SECONDS)
}
Method Name: navigate()
Syntax: WebDriver.Navigation navigate()
Purpose: An abstraction allowing the driver to access the browser's history and to navigate to a given URL.
Returns: A WebDriver.Navigation that allows the selection of what to do next
Example:
@Test
public void navigationToURLExample()
{
driver= new FirefoxDriver();
driver.get(URL);
System.out.println(driver.getTitle());
driver.navigate().to("http://www.google.com");
System.out.println(driver.getTitle());
}

@Test
public void navigationBackExample()
{
driver= new FirefoxDriver();
String URL="http://www.facebook.com";
driver.navigate().to(URL);
System.out.println(driver.getTitle());

driver.findElement(By.linkText("Forgot your password?")).click();
System.out.println(driver.getTitle());

driver.navigate().back();
System.out.println(driver.getTitle());
}

@Test
public void navigationForwardExample()
{
driver= new FirefoxDriver();
String URL="http://www.facebook.com";
driver.navigate().to(URL);
System.out.println(driver.getTitle());
driver.findElement(By.linkText("Forgot your password?")).click();
System.out.println(driver.getTitle());
driver.navigate().back();
System.out.println(driver.getTitle());
driver.navigate().forward();
System.out.println(driver.getTitle());
}

@Test
public void navigationRefreshExample()
{
driver= new FirefoxDriver();
String URL="http://www.facebook.com";
driver.navigate().to(URL);
driver.findElement(By.linkText("Forgot your password?")).click();
driver.findElement(By.id("identify_email")).sendKeys("sample@email.com");
driver.navigate().refresh();
}

January 4, 2013

Tutorial Database Testing using SQL

DataBase Management System (DBMS)

The software used for the management, maintenance and retrieval of the data stored in a database is called DBMS.

A database management system frees the programmer from the need to worry about the organization and location of data. The primary goal of a dbms is to provide an environment which is both convenient and efficient to use in retrieving and storing information.

A Database Storage Hierarchy

Database

A collection of data files integrated and organised into a simple comprehensive file system, which is arranged to minimize duplication of data and to provide convenient access to information within that system to satisfy a wide variety of user needs.

Data files

A file is a number of related records that are treated as a unit.

Ex: a collection of all employee records for one company would be an employee file.

Records

A collection of related items of data is treated as a unit.

Ex: an employee record would be collection of all fields of one employee.

Record is sometimes referred as tuple.

Field

Individual element of data is called field.

Ex: bank cheque consists of following field cheque no, date, payee, numeric amt, signature, bank, etc.

Field is sometimes referred as data item.

Basic DBMS Terms

Relation

A relationship is an association among several entities

Ex: a cusst_acct relationship associates a customer with each account that she or he has.

Redundancy

If same piece of information is stored in database for number of times the database is said to be redundant. We should check our database should not be redundant as it wastes make our disk space, reduced efficiency of database, require more processing time, and their chances of inconsistency due to it in our database.

Ex: if we have two tables emp_details (contains details of employee) and payroll (contains payment details to employee), than if we include details of employee in payroll table, than it is said to be redundancy as same piece of information is repeated.

Inconsistency

Inconsistency is various copies of the same data may no longer agree. Inconsistency occurs due to redundancy, so redundancy should be reduced. Though we cannot eliminate the redundancy, but we can reduce it up to certain level.

Ex: if we have details of employee stored in emp_details and payroll table than while updating information we should check that both tables are updated or not, if we update the address of one employee in emp_details and same details is not updated in payroll table, than database is said to be in inconsistent state.

Propagating updates

Propagating updates ensures users that any change made to record of one files, automatically made to other files. This process is known as propagating updates, where the term “updates” is used to cover all the operations of creation, deletion and modification.

We can avoid inconsistency by using propagating update technique.

Instances

The collection of information stored in the database at a particular moment in time is called instances of the database.

Schemas

The overall design of the database is called the database schemas. Schemas are changed infrequently, if at all.

Users

There are four different types of database system users.

Application programmers


A person who prepares application program are called application programmer. Application programs operate on the data in all the usual ways: retrieving information, creating new information, deleting or changing existing information.

Sophisticated users

Sophisticated users interact with the system without writing programs. Instead, they form their requests in a database query language. Each such query is submitted to a query processor whose function is to take a dml statement and break it down into instructions that the database manager understands.

Specialized users

Some sophisticated users write specialized database application that does not fit into the traditional data processing framework. Among these applications are computer-aided design systems, knowledge-base and expert systems, systems that store data with complex data types

Ex: For graphics and audio data.

End users

Unsophisticated users interact with the system by invoking one of the permanent application programs that have been written previously. Thus they are persons who use the information generated by a computer based system. Retrieval is the most common function for this class of user.

Keys concept in DBMS

A key is a single attribute or combination of two or more attributes of an entity set that is used to identify one or more instances of the set.

Primary key

A primary key is a field that uniquely identifies each record in a table. As it uniquely identifies each entity, it cannot contain null value and duplicate value.

Ex: consider the customer table, which has field: customer_number, customer_socialsecurity_number, and customer_address.here customer_number of each entity in customer table is distinct so customer-number can be a primary key of customer-table.

Super key

If we add additional attributes to a primary key, the resulting combination would still uniquely identify an instance of the entity set. Such augmented keys are called superkey.

A primary key is therefore a minimal superkey.

Candidate key

A nominee’s for primary key field are known as candidate key.

Ex: from above example of customer table, customer_socialsecurity_number is candidate key as it has all characteristics of primary key.

Alternate key

A candidate key that is not the primary key is called an alternate key.

Ex: in above example, customer_socialsecurity_number is a candidate key but not a primary key so it can be considered as alternate key.

Composite key

Creating more than one primary key are jointly known as composite key.

Ex: in above example, if customer_number and customer_socialsecurity_number are made primary key then they will be jointly known as composite key.

Foreign key

Foreign key is a primary key of master table, which is reference in the current table, so it is known as foreign key in the current table. A foreign key is one or more columns whose value must exist in the primary key of another table.

Ex: consider two tables emp(contains employees description) and emp_edu(contains details of employee’s education), so emp_id which is primary key in emp table will be referred as foreign key in emp_edu table.

Normalization

It is important to understand the concept of normalization before switch on to the creation of table and its manipulation.
  • Normalization is the process of grouping data into logical related groups.
  • Normalization is the process of reducing the redundancy of data in a relational database.
  • A database that is not normalized may include data that is contained in one or more different tables for no apparent reason. This could be bad for security reasons, disks space usage, speed of queries, efficiency of database updates, and may be most importantly, data integrity. A database before normalization is one that has not been broken down logically into smaller, more manageable tables.

Benefits of normalization:

Normalization provides numerous benefits to a database.

Some of the major benefits include wider the overall database organization.
  1. The reduction of redundant data.
  2. Data inconsistency can be avoided.
  3. A much more flexible database design.
  4. A better handle on database security.
The demand for "all round" testers, i.e. being able to test the system’s functionality through traditional testing methods and being able to show some technical knowledge are growing.
Basics of Database testing contain the following:

How to connect to the database?

Ability to write simple queries to retrieve data and manipulate the data using DML operations.
Functional flow should be very well known!
Good knowledge on table level, column level constraints, ability to understand and execute complex queries related to joins is added advantage.

INTRODUCTION TO DATABASE TESTING

  • Why back end testing is so important
  • Characteristics of back end testing
  • Back end testing phases
  • Back end test methods

STRUCTURAL BACK END TESTS

  1. Database schema tests
    1. Databases and devices
    2. Tables, columns, column types, defaults, and rules
    3. Keys and Indexes
  2. Stored procedure tests
    1. Individual procedure tests
    2. Integration tests of procedures
  3. Trigger tests
    1. Update triggers
    2. Insert triggers
    3. Delete triggers
  4. Integration tests of SQL server
  5. Server setup scripts
  6. Common bugs

FUNCTIONAL BACK END TESTS

  1. Dividing back end based on functionality
  2. Checking data integrity and consistency
  3. Login and user security
  4. Stress Testing
  5. Test back end via front end
  6. Benchmark testing
  7. Common bugs

TESTING THE NIGHTLY DOWNLOADING AND DISTRIBUTION JOBS

  1. Batch jobs
  2. Data downloading
  3. Data conversion
  4. Data distribution
  5. Nightly time window
  6. Common bugs

TESTING THE INTERFACES TO TRANSACTION APIS

  1. APIs' queries to back end
  2. Outputs of back end to APIs
  3. Common bugs

OTHER DATABASE TESTING ISSUES

  1. Test tips
  2. Test tools
  3. Useful queries

What are the difference between DDL, DML and DCL commands?

  1. DDL is Data Definition Language statements. Some examples:
    1. CREATE - to create objects in the database
    2. ALTER - alters the structure of the database
    3. DROP - delete objects from the database
    4. TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed
    5. COMMENT - add comments to the data dictionary
    6. GRANT - gives user's access privileges to database
    7. REVOKE - withdraw access privileges given with the GRANT command
  1. DML is Data Manipulation Language statements. Some examples:
    1. SELECT - retrieve data from the a database
    2. INSERT - insert data into a table
    3. UPDATE - updates existing data within a table
    4. DELETE - deletes all records from a table, the space for the records remain
    5. CALL - call a PL/SQL or Java subprogram
    6. EXPLAIN PLAN - explain access path to data
    7. LOCK TABLE - control concurrency.
  1. DCL is Data Control Language statements. Some examples:
    1. COMMIT - save work done
    2. SAVEPOINT - identify a point in a transaction to which you can later roll back
    3. ROLLBACK - restore database to original since the last COMMIT
    4. SET TRANSACTION - Change transaction options like what rollback segment to use
After reading part 1, now you are aware of –
  1. Why database testing is necessary?
  2. Differences between backend testing and front end testing
  3. Backend testing phases / Database Testing Phases
  4. Backend test methodology / Database Testing methodology
  5. Basics of SQL
Now let’s put more focus on SQL Statements –
  1. Section 1
    1. Basics of the SELECT Statement
    2. Conditional Selection
    3. Relational Operators
    4. Compound Conditions
    5. IN & BETWEEN
    6. Using LIKE
  2. Section 2
    1. Joins
    2. Keys
    3. Performing a Join
    4. Eliminating Duplicates
    5. Aliases & In/Sub-queries
  3. Section 3
    1. Aggregate Functions
    2. Views
    3. Creating New Tables
    4. Altering Tables
    5. Adding Data
    6. Deleting Data
    7. Updating Data
  4. Section 4
    1. Indexes
    2. GROUP BY & HAVING
    3. More Sub-queries
    4. EXISTS & ALL
    5. UNION & Outer Joins
    6. Embedded SQL
    7. Common SQL Questions
    8. Nonstandard SQL
    9. Syntax Summary