How to execute a scripts in Firefox and same scripts in IE .

How to execute a scripts in Firefox  and same   scripts in IE.

Default Asked on September 12, 2014 in Selenium WebDriver.
Add Comment
  • 2 Answer(s)

    Hi Akhilesh,

    Please go through this Link.

    Vice Professor Answered on September 12, 2014.
    Add Comment

    Hi Akhlish,

    WebDriver provides cross browser Script execution, for that you need to pass browser name using a properties / Excel file

    package test;

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.util.Properties;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;

    public class BrowserSelection {
    static WebDriver driver;
    public static void main(String args[])
    {
    BrowserSelection bs = new BrowserSelection();
    File file = new File(“C:\\workspace\\testng\\drivers\\”);
    try
    {
    String path = “C:\\workspace\\testng\\Input\\browser.properties”;
    Properties p = new Properties();
    InputStream is = new FileInputStream(path);
    p.load(is);
    switch(p.getProperty(“browser”))
    {
    case “chrome64” :
    System.setProperty(“webdriver.chrome.driver”, “”);
    driver = new ChromeDriver();
    bs.afterSelection(driver);
    break;
    case “chrome32” :
    System.setProperty(“webdriver.chrome.driver”, file.getAbsolutePath()+”\\chromedriver.exe”);
    driver = new ChromeDriver();
    bs.afterSelection(driver);
    break;
    case “firefox” :
    driver = new FirefoxDriver();
    driver.manage().window().maximize();
    bs.afterSelection(driver);
    break;
    case “ie64” :
    System.setProperty(“webdriver.ie.driver”, file.getAbsolutePath()+”\\IEDriverServer(x64).exe”);
    driver = new InternetExplorerDriver();
    bs.afterSelection(driver);
    driver.quit();
    break;
    case “ie32” :
    System.setProperty(“webdriver.ie.driver”, file.getAbsolutePath()+”\\IEDriverServer.exe”);
    driver = new InternetExplorerDriver();
    bs.afterSelection(driver);
    break;
    }
    is.close();
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    public void afterSelection(WebDriver driver)
    {
    BrowserSelection.driver = driver;
    driver.manage().window().maximize();
    driver.get(“http://www.google.com”);
    try {
    Thread.sleep(5000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    driver.quit();
    }
    }

    properties file contains the following attribute

    browser=ie32

    when you change the value of browser to chrome the code will execute in chrome browser

    Train Answered on September 15, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.