Best Testsigma code snippet using com.testsigma.agent.browsers.WindowsBrowsers.getVersionFromKey
Source:WindowsBrowsers.java
...118 if (!browserVersionFound) {119 for (String regEntryBrowser : currentUser32RegEntriesList) {120 log.info("Matching " + regEntryBrowser + " with browser key " + browserEntry.getValue());121 if (regEntryBrowser.contains(browserEntry.getValue())) {122 String version = getVersionFromKey(browserEntry.getValue());123 try {124 browserList.add(new AgentBrowser(browserEntry.getKey(), version, 0));125 } catch (Exception e) {126 log.info("Ignoring browser because of bellow error");127 log.error(e, e);128 }129 browserVersionFound = true;130 }131 }132 if (!browserVersionFound) {133 for (String regEntryBrowser : currentUser64RegEntriesList) {134 log.info("Matching " + regEntryBrowser + " with browser key " + browserEntry.getValue());135 if (regEntryBrowser.contains(browserEntry.getValue())) {136 String version = getVersionFromKey(browserEntry.getValue());137 try {138 browserList.add(new AgentBrowser(browserEntry.getKey(), version, 0));139 } catch (Exception e) {140 log.info("Ignoring browser because of bellow error");141 log.error(e, e);142 }143 }144 }145 }146 }147 }148 } catch (Exception e) {149 log.error(e.getMessage(), e);150 }151 }152 return browserList;153 }154 private String getBrowserVersion(Map.Entry<OsBrowserType, String> browserEntry) {155 String version = NOT_FOUND;156 int browserType = browserEntry.getKey().getValue();157 log.debug("Getting windows browser version for browser type - " + browserType);158 switch (browserType) {159 case 1:160 version = getChromeVersion();161 break;162 case 2:163 version = getFirefoxVersion();164 break;165 case 4:166 version = getEdgeVersion();167 break;168 }169 log.debug("Found browser " + browserEntry.getKey().name() + " with version - " + version);170 return version;171 }172 private String getEdgeVersion() {173 String version = NOT_FOUND;174 String edgeRegKey = searchRegistryByPattern(175 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\",176 ".*(Microsoft Edge.*)");177 if (StringUtils.isNotBlank(edgeRegKey)) {178 version = searchRegistryByPattern(179 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + edgeRegKey,180 ".*Version .* (.*)");181 }182 if (StringUtils.isBlank(version) || NOT_FOUND.equals(version)) {183 edgeRegKey = searchRegistryByPattern(184 "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\",185 ".*(Microsoft Edge.*)");186 if (StringUtils.isNotBlank(edgeRegKey)) {187 version = searchRegistryByPattern(188 "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"189 + edgeRegKey,190 ".*Version .* (.*)");191 }192 }193 if (StringUtils.isBlank(version) || NOT_FOUND.equals(version)) {194 String registryKey = "HKEY_CLASSES_ROOT\\Local Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppModel\\PackageRepository\\Packages";195 String regexPattern = ".*Microsoft.MicrosoftEdge_(.*)";196 String regValue = searchRegistryByPattern(registryKey, regexPattern);197 version = regValue.split("_")[0];198 }199 if (version.equals(NOT_FOUND))200 version = getBrowserVersionFromExe("Microsoft\\Edge\\Application\\msedge.exe");201 return version;202 }203 private String getChromeVersion() {204 String version = NOT_FOUND;205 String chromeRegKey = searchRegistryByPattern(206 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\",207 ".*(Google Chrome.*)");208 if (StringUtils.isNotBlank(chromeRegKey)) {209 version = searchRegistryByPattern(210 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + chromeRegKey,211 ".*Version .* (.*)");212 }213 if (StringUtils.isBlank(version) || NOT_FOUND.equals(version)) {214 chromeRegKey = searchRegistryByPattern(215 "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\",216 ".*(Google Chrome.*)");217 if (StringUtils.isNotBlank(chromeRegKey)) {218 version = searchRegistryByPattern(219 "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"220 + chromeRegKey,221 ".*Version .* (.*)");222 }223 }224 if (version.equals(NOT_FOUND))225 version = getBrowserVersionFromExe("Google\\Chrome\\Application\\chrome.exe");226 return version;227 }228 private String getFirefoxVersion() {229 String version = NOT_FOUND;230 String firefoxRegKey = searchRegistryByPattern(231 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\",232 ".*(Mozilla Firefox.*)");233 if (StringUtils.isNotBlank(firefoxRegKey)) {234 version = searchRegistryByPattern(235 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + firefoxRegKey,236 ".*Version .* (.*)");237 }238 if (StringUtils.isBlank(version) || NOT_FOUND.equals(version)) {239 firefoxRegKey = searchRegistryByPattern(240 "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\",241 ".*(Mozilla Firefox.*)");242 if (StringUtils.isNotBlank(firefoxRegKey)) {243 version = searchRegistryByPattern(244 "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"245 + firefoxRegKey,246 ".*Version .* (.*)");247 }248 }249 if (version.equals(NOT_FOUND))250 version = getBrowserVersionFromExe("Mozilla Firefox\\firefox.exe");251 return version;252 }253 private String searchRegistryByPattern(String registryKey, String regexPattern) {254 String result = NOT_FOUND;255 Pattern pattern = Pattern.compile(regexPattern);256 ArrayList<String> regEntriesList = searchRegistry(registryKey);257 for (String regKey : regEntriesList) {258 Matcher matcher = pattern.matcher(regKey);259 if (regKey.matches(pattern.pattern()) && matcher.find()) {260 result = matcher.group(1);261 break;262 }263 }264 return result;265 }266 public ArrayList<String> searchRegistry(String key) {267 Process process;268 String line;269 ArrayList<String> regEntriesList = new ArrayList<String>();270 ProcessBuilder processBuilder = new ProcessBuilder("reg", "query", key);271 try {272 process = processBuilder.start();273 BufferedReader bufferedReader = new BufferedReader(274 new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8));275 while ((line = bufferedReader.readLine()) != null) {276 regEntriesList.add(line);277 }278 } catch (Exception exception) {279 log.error("Error while fetching browser list - " + exception.getMessage(), exception);280 exception.printStackTrace();281 }282 return regEntriesList;283 }284 private String getVersionFromKey(String key) {285 String version = searchRegistryByPattern(286 "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + key,287 ".*Version .* (.*)");288 log.info("Matched HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + key289 + " and found version - " + version);290 if (StringUtils.isBlank(version) || NOT_FOUND.equals(version)) {291 version = searchRegistryByPattern(292 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + key,293 ".*Version .* (.*)");294 log.info("Matched HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + key295 + " and found version - " + version);296 if (StringUtils.isBlank(version) || NOT_FOUND.equals(version)) {297 version = searchRegistryByPattern(298 "HKEY_CURRENT_USER\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + key,...
getVersionFromKey
Using AI Code Generation
1WindowsBrowsers.getVersionFromKey("Software\\Microsoft\\Internet Explorer", "svcVersion")2WindowsBrowsers.getBrowserVersion("C:\\Program Files\\Internet Explorer\\iexplore.exe")3WindowsBrowsers.getBrowserVersion("C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe")4WindowsBrowsers.getBrowserVersion("C:\\Program Files\\Internet Explorer\\iexplore.exe", "Software\\Microsoft\\Internet Explorer")5WindowsBrowsers.getBrowserVersion("C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe", "Software\\Microsoft\\Internet Explorer")6WindowsBrowsers.getBrowserVersion("C:\\Program Files\\Internet Explorer\\iexplore.exe", "Software\\Microsoft\\Internet Explorer", "svcVersion")7WindowsBrowsers.getBrowserVersion("C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe", "Software\\Microsoft\\Internet Explorer", "svcVersion")8WindowsBrowsers.getBrowserVersion("C:\\Program Files\\Internet Explorer\\iexplore.exe", "Software\\Microsoft\\Internet Explorer", "svcVersion", "4.0")9WindowsBrowsers.getBrowserVersion("C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe", "Software\\Microsoft\\Internet Explorer", "svcVersion", "4.0")10WindowsBrowsers.getBrowserVersion("C:\\Program Files\\Internet Explorer\\iexplore.exe", "Software\\Microsoft\\Internet Explorer", "svcVersion", "4.0", "4.0")
getVersionFromKey
Using AI Code Generation
1String browserVersion = com.testsigma.agent.browsers.WindowsBrowsers.getVersionFromKey("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Google Chrome_is1");2String browserVersion = com.testsigma.agent.browsers.WindowsBrowsers.getVersionFromRegistry("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Google Chrome_is1", "DisplayVersion");3String browserVersion = com.testsigma.agent.browsers.WindowsBrowsers.getVersionFromRegistry("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Google Chrome_is1", "DisplayVersion");4String browserVersion = com.testsigma.agent.browsers.WindowsBrowsers.getVersionFromRegistry("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Google Chrome_is1", "DisplayVersion");5String browserVersion = com.testsigma.agent.browsers.WindowsBrowsers.getVersionFromRegistry("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Google Chrome_is1", "DisplayVersion");6String browserVersion = com.testsigma.agent.browsers.WindowsBrowsers.getVersionFromRegistry("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion
getVersionFromKey
Using AI Code Generation
1import com.testsigma.agent.browsers.WindowsBrowsers;2import com.testsigma.agent.core.TestSigma;3public class BrowserVersion {4 public static void main(String[] args) {5 TestSigma ts = new TestSigma();6 String browserVersion = WindowsBrowsers.getVersionFromKey("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");7 System.out.println(browserVersion);
getVersionFromKey
Using AI Code Generation
1def getVersionFromKey(String keyName, String keyPath) {2 try {3 key = new File(keyPath)4 def inputStream = new FileInputStream(key)5 def properties = new Properties()6 properties.load(inputStream)7 version = properties.getProperty(keyName)8 inputStream.close()9 } catch (Exception e) {10 e.printStackTrace()11 }12}13def getBrowserVersion(String browserName) {14 def browser = browserName.toLowerCase()15 def keyPath = System.getenv("LOCALAPPDATA") + "\\Google\\Chrome\\User Data\\Local State"16 if (browser == "chrome") {17 version = getVersionFromKey("version", keyPath)18 } else if (browser == "firefox") {19 keyPath = System.getenv("APPDATA") + "\\Mozilla\\Firefox\\profiles.ini"20 version = getVersionFromKey("Default", keyPath)21 } else if (browser == "ie") {22 version = getVersionFromKey("svcVersion", keyPath)23 } else if (browser == "edge") {24 version = getVersionFromKey("Version", keyPath)25 }26}27def getBrowserVersion(String browserName) {28 def browser = browserName.toLowerCase()29 def keyPath = System.getenv("LOCALAPPDATA") + "\\Google\\Chrome\\User Data\\Local State"30 if (browser == "chrome") {31 version = getVersionFromKey("version", keyPath)32 } else if (browser == "firefox") {33 keyPath = System.getenv("APPDATA") + "\\Mozilla\\Firefox\\profiles.ini"34 version = getVersionFromKey("Default", keyPath)35 } else if (browser == "ie") {36 version = getVersionFromKey("svcVersion", keyPath)37 } else if (browser == "edge") {
getVersionFromKey
Using AI Code Generation
1import com.testsigma.agent.browsers.WindowsBrowsers;2WindowsBrowsers windowsBrowsers = new WindowsBrowsers();3String version = windowsBrowsers.getVersionFromKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION", "iexplore.exe");4System.out.println("IE version is " + version);5if(version.equals("11.0")){6}7else if(version.equals("10.0")){8}9else if(version.equals("9.0")){10}11else{12}13import com.testsigma.agent.browsers.WindowsBrowsers;14WindowsBrowsers windowsBrowsers = new WindowsBrowsers();15String version = windowsBrowsers.getVersionFromKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION", "iexplore.exe");16System.out.println("IE version is " + version);17if(version.equals("11.0")){18}19else if(version.equals("10.0")){20}21else if(version.equals("9.0")){22}23else{24}25import com.testsigma.agent.browsers.WindowsBrowsers;26WindowsBrowsers windowsBrowsers = new WindowsBrowsers();27String version = windowsBrowsers.getVersionFromKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION", "iexplore.exe");28System.out.println("IE version is " + version);
getVersionFromKey
Using AI Code Generation
1import com.testsigma.agent.browsers.Browsers;2import com.testsigma.agent.browsers.WindowsBrowsers;3WindowsBrowsers wb = new WindowsBrowsers();4String version = wb.getVersionFromKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe");5System.out.println(version);6Browsers b = new Browsers();7String version = b.getBrowserVersion(Browsers.Browser.CHROME);8System.out.println(version);9import com.testsigma.agent.browsers.Browsers;10import com.testsigma.agent.browsers.WindowsBrowsers;11WindowsBrowsers wb = new WindowsBrowsers();12String version = wb.getVersionFromKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\App Paths\\firefox.exe");13System.out.println(version);14Browsers b = new Browsers();15String version = b.getBrowserVersion(Browsers.Browser.FIREFOX);16System.out.println(version);17import com.testsigma.agent.browsers.Browsers;18import com.testsigma.agent.browsers.WindowsBrowsers;19WindowsBrowsers wb = new WindowsBrowsers();20String version = wb.getVersionFromKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\App Paths\\iexplore.exe");21System.out.println(version);22Browsers b = new Browsers();23String version = b.getBrowserVersion(Browsers.Browser.INTERNET_EXPLORER);24System.out.println(version);
getVersionFromKey
Using AI Code Generation
1String browserVersion = WindowsBrowsers.getVersionFromKey("HKEY_CURRENT_USER\\Software\\Google\\Chrome\\BLBeacon", "version");2int browserVersionNum = browserVersion.toInteger();3String browserVersion = WindowsBrowsers.getVersionFromKey("HKEY_CURRENT_USER\\Software\\Google\\Chrome\\BLBeacon", "version");4int browserVersionNum = browserVersion.toInteger();5String browserVersion = WindowsBrowsers.getVersionFromKey("HKEY_CURRENT_USER\\Software\\Google\\Chrome\\BLBeacon", "version");6int browserVersionNum = browserVersion.toInteger();7String browserVersion = WindowsBrowsers.getVersionFromKey("HKEY_CURRENT_USER\\Software\\Google\\Chrome\\BLBeacon", "version");8int browserVersionNum = browserVersion.toInteger();9String browserVersion = WindowsBrowsers.getVersionFromKey("HKEY_CURRENT_USER\\Software\\Google\\Chrome\\BLBeacon", "version");10int browserVersionNum = browserVersion.toInteger();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!