How to run Selenium tests in multiple browsers for cross-browser testing using Java?

前端 未结 4 1837
青春惊慌失措
青春惊慌失措 2020-12-06 08:37

I am using Selenium WebDriver with Java & TestNG framework. I want to use Firefox, IE, Chrome in one single code at a time for doing cross-browser testing. I can only in

4条回答
  •  执笔经年
    2020-12-06 09:15

    For C#

    Add

    using OpenQA.Selenium.Chrome;
    using OpenQA.Selenium.Firefox;
    using OpenQA.Selenium.IE;
    

    Create a config file which will contain browser name. Implement a method for interaction with the config file

    And you can use below code for initialize browsers:

    string browser = GetConfigProperty("browser"); //Get browser name from the config
            switch (browser)
            {
                case "chrome":
                    driver = new ChromeDriver();
                    break;
                case "firefox":
                    driver = new FirefoxDriver();
                    break;
                case "InternetExplorer":
                    driver = new InternetExplorerDriver();
                    break;
            }
    

    good luck!

提交回复
热议问题