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,

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.