Monday 14 November 2016

Get site address from text file and launch it(VIDEO)(Webdriver)

Hi,

Earlier we have seen that how we can read a data from a text file and print that in console.In that we have only used java functions and methods

Now we will be seeing that how we can read a site address from the file and launch it in a browser using webdriver and its functions.This method help in testing multiple sites where we have test cases that check with multiple sites in a single test case.Using this method it is more convenient and time effective as well.

For this we just have to add few codes in last script where we were reading the content of a file.we just have to create instance of webdriver and use the get function instead of system.out.println() function.



SCRIPT FOR GETTING SITE ADDRESS FROM A TEXT FILE


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class seleniumfirstscript  {
 public static void main(String[] args)
 {
WebDriver driver;
System.setProperty("webdriver.chrome.driver","d:/chromedriver.exe");
driver=new ChromeDriver();
       String path = "D:\\test.txt";
       FileReader file = null;
       BufferedReader read  = null;
     try{
     String sCurrentLine;
     file =  new FileReader(path);
     read = new BufferedReader(file);
     while ((sCurrentLine = read.readLine()) != null)
     {
    driver.get(sCurrentLine);
     }
 }catch(IOException e)
 {
System.out.println(e.getMessage());
 }
}

}

0 comments: