Environment details, browser version and browser name using selenium

package locators;
import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;

public class SeleniumLocators {
    WebDriver driver;

    @Test
        public void printBrowerNameandVersionNameandOSName2() throws Exception {
            JavascriptExecutor js = (JavascriptExecutor)driver;
            String s = (String)js.executeScript("return navigator.userAgent;");

            System.out.println("Browser name : " + s);
            driver.get("http://www.seleniumlearn.com");
        }
    

    @BeforeTest
    public void beforeTest() {
        driver=new FirefoxDriver();
        //System.setProperty("webdriver.chrome.driver","D:\\lib\\chromedriver.exe"); //---> Chromedriver path
        //driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(9,TimeUnit.SECONDS);
        driver.manage().window().maximize();

    }

}

Comments