How to change web browser from Firefox to Chrome/Opera/IE/Safari in selenium webdriver?

后端 未结 1 1149
长发绾君心
长发绾君心 2021-02-15 12:31

How to change browser from firefox to Chrome/Opera/IE working in selenium webdriver? Please guide in steps and also with the code snippet.

Please reply if you have answe

1条回答
  •  面向向阳花
    2021-02-15 12:56

    First of all you need to import the proper drivers into the project/class.

    like

    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    

    etc.

    The you need to create new Webdrivers for the broswer you need.

    like

    WebDriver driver = new FirefoxDriver();
    WebDriver driver = new InternetExplorerDriver();
    WebDriver driver = new ChromerDriver();
    

    etc for each browser.

    NOTE: It is tough to use different browsers/drivers in a single test. Either you may use similar tests for each browser and maintain a test-suite (i.e. use one driver and import in a test and maintain similar test for other browsers) or you can use some config files or excel to pick up which browser you want the test to run. You might like to explore http://htmlunit.sourceforge.net/ for headless testing.

    And information about OperaDriver can be found here: - https://github.com/operasoftware/operadriver/

    0 讨论(0)
提交回复
热议问题