The blog gives you idea of testing and automation testing example of selenium webdriver,SQl and Jmeter, you see the basic example of selenium web driver and get idea how to do automation testing,

Automation Frame Work

Automation Frameworks: Suppose you have a task where you want to automate some test cases a application. When you are finished automating of the application, what would be your expectations from the scripts you have created? Wouldn’t you want that –

1) scripts should be run as without any issues.
2) code and the flows should be easy to understand.
3) Scripts should be simple and easy to maintain.

Above points can be achieved by using Automation Framework.

Automation Framework is a set of guidelines that you can follow during test case scripting to achieve the above mentioned results. This set of guidelines can be anything such as –

1) Specifying the folder structure that will be used for storing test cases, function libraries, object repositories and data sheets.
2) Deciding the format of the data sheets i.e., how the data sheets would be grouped and how the scripts will access these data sheets.
3) Following proper coding standards and using comments so that the code can be understood easily by anyone.
4) Using reusable functions wherever possible so that lesser amount of rework is needed in case of any changes

Follow the guidelines (that you have set) while you are creating the test scripts would result in the creation of an end product(your Automation Framework) that include all the features which you had targeted for.

Types of Frameworks

1.Keyword framework
2.Datadriven framework
3.Modular framework
4.Hybrid framework.

1.Keyword framework
      Keyword Driven framework, you can create various keywords and associate a different action or function with each of these keywords. Then you create a Function Library that contains the logic to read the keywords and call the associated action. To read data you have to create logic in you code. (In Project you have to a class of utils so all reuse method or function should return in this)
Advantages of Keyword Driven Framework
1) The keyword and function libraries are completely generic and thus can be reused easily for different applications.
2) All the complexity is added in the function libraries. Once the libraries are ready, it becomes very easy to write the actual test script steps in excel sheets.

Disadvantages of Keyword Driven Framework
1) Lot of time and effort needs to be spent initially to create the function libraries. The benefits of the keyword driven framework are realized only after it has been used for longer periods of time.
2)Very high programming skills are needed to create the complex keyword library functions.
3)It’s not easy for new people to understand the framework quickly.

2.Data-driven framework
      In Data Driven Framework, the data is NOT hard-coded in the test scripts. all data are stored in some external files. The test script first connects to the external data source and then extracts the data from that source. Most of the times, excel sheets(Data should be enter in Excel sheet and read data from excel sheet) are used to store the data. Other external data sources that are frequently used are –
1) Text files.
2) XML files.
3) Databases.
4) Combination of more than one external file.
Advantages of Data Driven Framework
1) Since the data is kept separate from the test script, the same script can be run multiple times for different sets of data (which can be kept in multiple rows in the data sheet).
2) Changes made in the test data don’t affect the test scripts in any way and vice versa.
Disadvantages of Data Driven Framework
1) Additional effort and good technical expertise is required to create functions that connect to the external data sources to retrieve the data.
2) Additional amount of time is required in identifying which external data source to use and deciding how the data should be stored or grouped in that external data source.

3.Modular framework
   Modular Framework is the approach where all the test cases are first analysed to find out the reusable flows. Then while scripting, all these reusable    
   flows are created as functions and stored in external files and called in the test scripts wherever required.

Advantages of Modular Framework
1) Test Scripts can be created in relatively less time as the reusable functions need to be created only once.
2) Effort required to create test cases is also lesser due to code reuse.
3) If there are any changes in the reusable functions, the changes need to be done in only a single place. Hence script maintenance is easier.
Disadvantages of Modular Framework
1) Since data is still hard coded in the script, the same test case cannot be run for multiple data values without changing data after each run.
2) Additional time is spent in analyzing the test cases to identify with reusable flows.
3) Good programming knowledge is required to create and maintain function libraries.

4.Hybrid framework.
      Hybrid Framework is a combination of other framework  or it is created by combining different features of any of the frameworks mentioned above. Based upon your requirements, you can combine the features of any of the above frameworks to come up with your own version of Hybrid Framework.

Advantages of Hybrid Framework
1) The main advantage of this approach is that you can use the best features from all the types of frameworks to create your own.
Disadvantages of Hybrid Framework
1) The framework is highly complex and needs very good programming expertise and experience to build a Hybrid Framework from scratch.

Browser Back & Forward in selenium webdriver

while testing application if you get a scenario of browser back and Forward then how you will handle it in automation script. when I was writing automation script, I am get multiple scenario of browser back and forward in my application testing for that  I am using below code in our script.


Follow below step:
1. Create Driver for any Browser(Mozilla)
2. Go to the URL
3. Navigate to some page in website.
4. Use Selenium code to Navigate Back to Main Page.

public void  browserBack(){

public static void main(String args[]){
WebDriver driver =new FirefoxDriver();
driver.get("http://seleniumhq.org/");
driver.findElement(By.linkText("Download")).click();
Thread.sleep(3000);            //delay in time
driver.navigate().back();
Thread.sleep(3000);            //delay in time
driver.navigate().forward();
        }
}

Move all file from one directory to other directory

In programming you can move file from one location to another, if you move file from one location to another then that is not available on original file it move to another location .
this code help when you have multiple file in one location with different extension and you want to move file of specific extension for example you want all .pdf file then below code will guide you how to move file
Below is the code of move file:


package sumadding;

import java.io.File;
import java.io.IOException;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public class FileMove {

String destinationFilePath = "C:\\Users\\xyz\\workspace\\adding\\Destination\\";
String sourceFilePath = "C:\\Users\\xyz\\workspace\\adding\\";
File sourceFile = new File(sourceFilePath);


public void testing() throws IOException {
File[] files = sourceFile.listFiles();
CopyOption[] options = new CopyOption[]{
};
if(sourceFile != null)
{
for(File file:files)
{
if(file.isFile())
{
String fileName = file.getName();
String path = file.getPath();
String extension = fileName.substring(fileName.lastIndexOf("."));
if(extension.equalsIgnoreCase(".pdf"))
{
File srcPath = new File(path);
destinationFilePath =  destinationFilePath.concat(fileName);
File destinationFile = new File(destinationFilePath);
                                         // This line move your file from one location to another
Files.move(srcPath.toPath(), destinationFile.toPath(), options);
System.out.print("File Copied Successfull");
}
}
else
{
System.out.println("Is a Directory");
}
}
         }
else
{
System.out.print("File does not Copied ");
}

}
public static void main(String[] args) throws IOException {
FileMove f = new FileMove();
f.testing();
}

}

how to read data from object properties files

If we read data from properties file then it help us to avoid the recompilation of program if any changes in done related to properties. It is handy to maintain and update the properties file.
If any changes in required in validation, warning, success or any information message then we have to change only properties file and that message will get reflected which help us to avoid any changes in java code.

Below is  the steps to implemented of properties file

1) create a properties file and below is code :

Name of propeties file : homePath.properties

homeLink=linkText:HOME
homeArticle=linkText:ARTICLES

2) create a single ton class of webdriver:

import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class elementdetials {
static WebDriver webDriver=null;
public static WebDriver webDriver(){
if(webDriver==null)
{
webDriver= new FirefoxDriver();
}
return webDriver;
}

//public WebElement submenu;
public static String baseurl = "http://www.bloghuts.com";
 public void takeScreenShot(String methodName) {
    //get the driver
   String filePath= "user.dir";
    File scrFile = ((TakesScreenshot)webDriver).getScreenshotAs(OutputType.FILE);
        //The below method will save the screen shot in d drive with test method name
           try {
FileUtils.copyFile(scrFile, new File(filePath+"\\Screenshot\\" + methodName+".png"));
System.out.println("***Placed screen shot in "+filePath+" ***");
} catch (IOException e) {
e.printStackTrace();
}
   }

}

3) create a Java file and below is code:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import defineelement.ObjectMap;
import defineelement.elementdetials;

public class ActualTesting {
static WebDriver driver = elementdetials.webDriver();
static ObjectMap objectMap = new ObjectMap();

public WebElement getXpathData(String xpath) throws Exception {
WebElement getPathData= driver.findElement(objectMap.getLocator(xpath));
return getPathData;
}
public void testBloghunt() throws Exception {

   driver.get("https://www.bloghuts.com/");
   try {
     Assert.assertEquals("HOME", getXpathData("homeLink").getText());
     if(getXpathData("homeLink").getText().equals("HOME")){
     System.out.println("Text Match is Pass");
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   try {
    Assert.assertEquals("ARTICLES", getXpathData("homeArticle").getText());
    System.out.println("Article Text Match is Pass");
   } catch (Exception e) {
    e.printStackTrace();
   }
 }
public static void main(String[] args) throws Exception {
ActualTesting t = new ActualTesting();
t.testBloghunt();
}

}

Powered by Blogger.