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,

Take screen shot of page when method failed

Take screeenshot will take images when any method is fail or execution stop some how, let example in automation we user assert to verify values when there is some changes in application then assert is fail and it throw some exception so in exception if we add takescreenshot("Parameter name")  method then it will take sscreen shot of fail page.



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;

public class elementdetials {

/**If this method Fail then screen show take and stored in folder**/
     public void onTestFailure(ITestResult result) {
                   WebDriver driver = new FirefoxDriver();
                   driver.get("https://qamanual.blogspot.com");
  driver.manage().window().maximize();
WebElement headerelement = driver.findElement(By.linkText("HOME"));
                try{
                                 Assert.assertEquals("Home",headerelement.getText());
                    }
catch (IOException e) {
e.printStackTrace();
                                 takeScreenShot(methodName);
}
               }
 public void takeScreenShot(String methodName) {
   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();
}
   }

}

how to create Single ton Class in selenium webdriver

In selenium if we create a single ton class, it means we create a single instance of that class and we can use single instance at multiple places, below is the code which you give a brief idea of single ton class. Since there is only one Singleton instance, any instance fields of a Singleton will occur only once per class, just like static fields
In we use single instance of webdriver it means only one browser would open at a time

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

1) it is one class 
public class elementdetials {
static WebDriver webDriver=null;
public static WebDriver webDriver(){
if(webDriver==null)
{
webDriver= new FirefoxDriver();
}
return webDriver;
}

2) I created a another class on same or different package and in that class I will create this webdriver.

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.interactions.Actions;

import defineelement.elementdetials;

public class  Cssfind extends homepageclick{
/**Create single instance of webdriver.**/
static WebDriver driver = elementdetials.webDriver();
public void FirefoxProfile () {
ProfilesIni profile = new ProfilesIni();
    org.openqa.selenium.firefox.FirefoxProfile ffprofile =                
              profile.getProfile("Profiles/1le2ettt.default");
  }
    /** Open url **/
  public void openurl(){

driver.get(elementdetials.baseurl);
}
/** Maximumsize of Windows **/
public void maximumwindows()
{
driver.manage().window().maximize();
System.out.println("Current url of page" + driver.getCurrentUrl());

}
/**Check header or data of applicaiton**/
public void header ()
{
    WebElement lockcss = driver.findElement(By.cssSelector(".col-md-3"));
    String a = lockcss.getCssValue("color");
    String bordercolor = lockcss.getCssValue("font-family");
System.out.println("testing" + a);
System.out.println("testing" + bordercolor);
WebElement a1 = driver.findElement(By.cssSelector(".flexnev_home"));
System.out.println(a1 );
}
}
Powered by Blogger.