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,

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();
}

}

No comments

Post a Comment

Powered by Blogger.