0

I want to run same test in multiple browsers: What should be the required code in my configuration file?
Here is my code, what I have tried:

package util;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class DriverManager {
    public static WebDriver driver;
    String baseUrl="http://--";
    public DriverManager()
    {
        System.setProperty("webdriver.chrome.driver","/home/naveen/chromedriver");
        driver=new ChromeDriver();
        driver.get(baseUrl);
        driver.manage().window().maximize();
    }
}

Help me- What should I need to do changes in my above code for Running same test on multiple browsers Like-Chrome, Mozilla, IE...etc?

  • Are you looking for parallel running of browser ? – Gaurav Jan 23 '17 at 12:39
  • 1
    Not sure why closing mafia is running amok again closing this question. It is VERY OBVIOUS what is OP asking: how to parametrize the browser running the test. Some people are drunk with power to close the questions they recently gained. This is ABUSE OF POWER, if you ask me. – Peter M. - stands for Monica Jan 23 '17 at 17:05
  • 1
    BTW: Is "toastmaster" just a sock puppet for Antony Naveen? Why else would tostmaster's code be in the "naveen" directory? – Peter M. - stands for Monica Jan 23 '17 at 18:37
  • You can check detailed answer here: guru99.com/cross-browser-testing-using-selenium.html – Bharat Mane Mar 7 '17 at 9:00
1

If I get your question correctly you want to run the same script in different browsers Then, write a method pass a browser name as a string, use a 'switch case' logic to determine which browser to initiate.

Demo code is as below:

public void open_Browser(String browserName) 
    {
        try 
        {
            System.out.printf("Opening %s browser.\n", browserName);

            switch (browserName)
            {
                case "firefox":
                {
                    System.setProperty("webdriver.gecko.driver","./Configuration File/geckodriver.exe");
                    driver = new FirefoxDriver();

                    break;
                }
                case "chrome":
                {
                    System.setProperty("webdriver.chrome.driver","./Configuration File/chromedriver.exe");
                    driver = new ChromeDriver();

                    break;
                }
                case "ie":
                {
                    System.setProperty("webdriver.ie.driver","./configuration_and_resources/IEdriverServer.exe");
                    driver = new InternetExplorerDriver(capabilities);

                    break;
                }

                default:
                    break;
            }
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    }
1

Use WebDriver.for, e.g.

require 'selenium-webdriver'
require 'rspec-expectations'

def setup(platform, browser_name, browser_version)
  caps = Selenium::WebDriver::Remote::Capabilities.send(browser_name.to_sym)
  caps.platform = platform
  caps.version = browser_version.to_s

  @driver = Selenium::WebDriver.for(
    desired_capabilities: caps)
  end

  def teardown
    @driver.quit
  end
end
0

If you mean in you question how to launch test on the multiple instances of different browsers, you should use cloud based tools, as SauceLabs, BrowserStack or Blazemeter, that help you to scale up your tests. To use cloud solution for launching you tests in multiple browsers is justified, as any browser requires considerable resources, as CPU and RAM. If launching tests in multiple browsers pursues the purpose to create a load, than you should to use webdriver sampler in Jmeter or Taurus + Selenium to scale up selenium tests and Blazemeter to launch them in the cloud. If it's what you are looking for you may find more details in the post https://www.blazemeter.com/blog/can-you-run-performance-test-100000-real-browsers .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.