Best Testsigma code snippet using com.testsigma.agent.browsers.WindowsBrowsers.searchRegistry
Source:WindowsBrowsers.java
...73 public ArrayList<AgentBrowser> getBrowserList() throws Exception {74 ArrayList<AgentBrowser> browserList = new ArrayList<>();75 int arch = System.getProperty("os.arch").contains("64") ? 64 : 32;76 String nodeValue = (arch == 32) ? "" : "WOW6432Node";77 ArrayList<String> localMachine32RegEntriesList = searchRegistry(78 "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Clients\\StartMenuInternet");79 ArrayList<String> currentUser32RegEntriesList = searchRegistry(80 "HKEY_CURRENT_USER\\SOFTWARE\\WOW6432Node\\Clients\\StartMenuInternet");81 ArrayList<String> localMachine64RegEntriesList = searchRegistry(82 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Clients\\StartMenuInternet");83 ArrayList<String> currentUser64RegEntriesList = searchRegistry(84 "HKEY_CURRENT_USER\\SOFTWARE\\Clients\\StartMenuInternet");85 for (Entry<OsBrowserType, String> browserEntry : browsersMap.entrySet()) {86 log.debug("Getting version for windows browser : " + browserEntry.getKey() + " - " + browserEntry.getValue());87 try {88 boolean browserVersionFound = false;89 for (String regEntryBrowser : localMachine32RegEntriesList) {90 log.info("Matching " + regEntryBrowser + " with browser key " + browserEntry.getValue());91 if (regEntryBrowser.contains(browserEntry.getValue())) {92 String version = getBrowserVersion(browserEntry);93 try {94 browserList.add(new AgentBrowser(browserEntry.getKey(), version, 0));95 } catch (Exception e) {96 log.info("Ignoring browser because of bellow error");97 log.error(e, e);98 }99 browserVersionFound = true;100 break;101 }102 }103 if (!browserVersionFound) {104 for (String regEntryBrowser : localMachine64RegEntriesList) {105 log.info("Matching " + regEntryBrowser + " with browser key " + browserEntry.getValue());106 if (regEntryBrowser.contains(browserEntry.getValue())) {107 String version = getBrowserVersion(browserEntry);108 try {109 browserList.add(new AgentBrowser(browserEntry.getKey(), version, 0));110 } catch (Exception e) {111 log.info("Ignoring browser because of bellow error");112 log.error(e, e);113 }114 browserVersionFound = true;115 break;116 }117 }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,299 ".*Version .* (.*)");300 log.info("Matched HKEY_CURRENT_USER\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + key301 + " and found version - " + version);302 if (StringUtils.isBlank(version) || NOT_FOUND.equals(version)) {303 version = searchRegistryByPattern(304 "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + key,305 ".*Version .* (.*)");306 log.info("Matched HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + key307 + " and found version - " + version);308 }309 }310 }311 return version;312 }313}...
searchRegistry
Using AI Code Generation
1import com.testsigma.agent.browsers.WindowsBrowsers2WindowsBrowsers searchRegistry = new WindowsBrowsers()3searchRegistry.searchRegistry()4import com.testsigma.agent.browsers.WindowsBrowsers5WindowsBrowsers searchRegistry = new WindowsBrowsers()6searchRegistry.searchRegistry()7import com.testsigma.agent.browsers.WindowsBrowsers8WindowsBrowsers searchRegistry = new WindowsBrowsers()9searchRegistry.searchRegistry()10import com.testsigma.agent.browsers.WindowsBrowsers11WindowsBrowsers searchRegistry = new WindowsBrowsers()12searchRegistry.searchRegistry()13import com.testsigma.agent.browsers.WindowsBrowsers14WindowsBrowsers searchRegistry = new WindowsBrowsers()15searchRegistry.searchRegistry()16import com.testsigma.agent.browsers.WindowsBrowsers17WindowsBrowsers searchRegistry = new WindowsBrowsers()18searchRegistry.searchRegistry()19import com.testsigma.agent.browsers.WindowsBrowsers20WindowsBrowsers searchRegistry = new WindowsBrowsers()21searchRegistry.searchRegistry()22import com.testsigma.agent.browsers.WindowsBrowsers23WindowsBrowsers searchRegistry = new WindowsBrowsers()24searchRegistry.searchRegistry()25import com.testsigma.agent.browsers.WindowsBrowsers26WindowsBrowsers searchRegistry = new WindowsBrowsers()27searchRegistry.searchRegistry()28import com.testsigma.agent.browsers.WindowsBrowsers29WindowsBrowsers searchRegistry = new WindowsBrowsers()30searchRegistry.searchRegistry()31import com.testsigma.agent.browsers.WindowsBrowsers32WindowsBrowsers searchRegistry = new WindowsBrowsers()33searchRegistry.searchRegistry()
searchRegistry
Using AI Code Generation
1WindowsBrowsers windowsBrowsers = new WindowsBrowsers();2windowsBrowsers.searchRegistry("chrome", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");3WindowsBrowsers windowsBrowsers = new WindowsBrowsers();4windowsBrowsers.searchRegistry("firefox", "C:\\Program Files\\Mozilla Firefox\\firefox.exe");5WindowsBrowsers windowsBrowsers = new WindowsBrowsers();6windowsBrowsers.searchRegistry("ie", "C:\\Program Files\\Internet Explorer\\iexplore.exe");7WindowsBrowsers windowsBrowsers = new WindowsBrowsers();8windowsBrowsers.searchRegistry("edge", "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");9WindowsBrowsers windowsBrowsers = new WindowsBrowsers();10windowsBrowsers.searchRegistry("safari", "C:\\Program Files\\Safari\\Safari.exe");11WindowsBrowsers windowsBrowsers = new WindowsBrowsers();12windowsBrowsers.searchRegistry("opera", "C:\\Program Files\\Opera\\launcher.exe");13WindowsBrowsers windowsBrowsers = new WindowsBrowsers();14windowsBrowsers.searchRegistry("phantomjs", "C:\\Program Files\\phantomjs\\bin\\phantomjs.exe");15WindowsBrowsers windowsBrowsers = new WindowsBrowsers();16windowsBrowsers.searchRegistry("chromium", "C:\\Program Files\\Chromium\\Application\\chromium.exe");17WindowsBrowsers windowsBrowsers = new WindowsBrowsers();18windowsBrowsers.searchRegistry("brave", "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe");
searchRegistry
Using AI Code Generation
1WindowsBrowsers searchRegistry = new WindowsBrowsers();2searchRegistry.searchRegistry("chrome");3WindowsBrowsers getBrowserVersion = new WindowsBrowsers();4getBrowserVersion.getBrowserVersion("chrome");5WindowsBrowsers getBrowserInstallPath = new WindowsBrowsers();6getBrowserInstallPath.getBrowserInstallPath("chrome");7WindowsBrowsers getBrowserInstallPath = new WindowsBrowsers();8getBrowserInstallPath.getBrowserInstallPath("chrome");9WindowsBrowsers getBrowserInstallPath = new WindowsBrowsers();10getBrowserInstallPath.getBrowserInstallPath("chrome");11WindowsBrowsers getBrowserInstallPath = new WindowsBrowsers();12getBrowserInstallPath.getBrowserInstallPath("chrome");
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!!