Reading a Windows registry value from Selenium WebDriver
The WindowsUtils
class provides various methods to interact with the registry on the Windows operating system. While running tests on the Windows operating system and Internet Explorer, the test might need to read and modify IE settings or there may be a need to get some settings related to the web server or database from the registry in tests. The WindowsUtils
class comes handy in these situations.
In this recipe, we will use WindowsUtil
to read the exact name of the operating system on which the test is running. We might need this information printed in our test logs.
How to do it...
We need to import the org.openqa.selenium.os.WindowsUtils
class and use the readStringRegistryValue()
method for reading a registry value that is represented as a String
.
String osname = WindowsUtils.readStringRegistryValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProductName"); System.out.println(osname);
How it works...
The WindowsUtils...