From d55b9f0e75b969fb4b3e866459f68e893cb60d20 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Mon, 16 Jan 2023 16:19:16 +0100 Subject: [PATCH 1/8] fix parsing of chromedriver version --- src/main/java/testUI/AndroidUtils/ADBUtils.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/testUI/AndroidUtils/ADBUtils.java b/src/main/java/testUI/AndroidUtils/ADBUtils.java index 35ab99f..92ad280 100644 --- a/src/main/java/testUI/AndroidUtils/ADBUtils.java +++ b/src/main/java/testUI/AndroidUtils/ADBUtils.java @@ -369,15 +369,12 @@ private static String getChromedriverVersion(String chromeVersion) { putLogWarn("Could not connect to \"https://chromedriver.storage.googleapis.com/\""); return "80"; } - String chromeDriverVersion = ""; // ToDo it is not pulling the version. I just - String new_chrome_version = ""; - for (String text : body.split(version)) { + String chromeDriverVersion = ""; + for (String text : body.split(">" +version)) { if (text.contains("/chromedriver_mac64.zip")) { - new_chrome_version = - version + text.split("/chromedriver_mac64\\.zip")[0]; + if (text.split("/chromedriver_mac64\\.zip")[0].length() < 17) + chromeDriverVersion = version + text.split("/chromedriver_mac64\\.zip")[0]; } - if (new_chrome_version.length() < 17) - chromeDriverVersion = new_chrome_version; } return chromeDriverVersion; } From b8bc2e18146e73ce373e0bb1f8a0292835a02f9c Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Mon, 23 Jan 2023 14:05:47 +0200 Subject: [PATCH 2/8] parse xml better --- .../java/testUI/AndroidUtils/ADBUtils.java | 61 ++++++++++++++++--- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/src/main/java/testUI/AndroidUtils/ADBUtils.java b/src/main/java/testUI/AndroidUtils/ADBUtils.java index 92ad280..a9d56a4 100644 --- a/src/main/java/testUI/AndroidUtils/ADBUtils.java +++ b/src/main/java/testUI/AndroidUtils/ADBUtils.java @@ -6,13 +6,20 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; import testUI.TestUIConfiguration; import testUI.Utils.TestUIException; -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.*; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; @@ -370,12 +377,50 @@ private static String getChromedriverVersion(String chromeVersion) { return "80"; } String chromeDriverVersion = ""; - for (String text : body.split(">" +version)) { - if (text.contains("/chromedriver_mac64.zip")) { - if (text.split("/chromedriver_mac64\\.zip")[0].length() < 17) - chromeDriverVersion = version + text.split("/chromedriver_mac64\\.zip")[0]; + String chromeName = ""; + String Platform = System.getProperty("os.name").toLowerCase(); + if (Platform.contains("mac")) { + if (System.getProperty("os.arch").toLowerCase().contains("aarch64")) { + chromeName = "/chromedriver_mac64_m1.zip"; + } else { + chromeName = "/chromedriver_mac64.zip"; + } + } else if (Platform.contains("linux")) { + chromeName = "/chromedriver_linux64.zip"; + } else { + chromeName = "/chromedriver_win32.zip"; + } + Document doc = loadXMLFromString(body); + // Getting each of the chrome driver versions from the chromium api + NodeList list = doc.getDocumentElement().getElementsByTagName("Contents"); + + for (int temp = 0; temp < list.getLength(); temp++) { + Node node = list.item(temp); + if (node.getNodeType() == Node.ELEMENT_NODE) { + Element element = (Element) node; + + String text = element.getTextContent(); + // Check that the version and platform matches + if (text.startsWith(version) && text.contains(chromeName)) { + chromeDriverVersion = text.split(chromeName)[0]; + } } } + return chromeDriverVersion; } + + private static Document loadXMLFromString(String xmlString) + { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + try { + dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + DocumentBuilder builder = dbf.newDocumentBuilder(); + Document doc = builder.parse(new InputSource(new StringReader(xmlString))); + return doc; + + } catch (ParserConfigurationException | IOException | SAXException e) { + throw new RuntimeException(e); + } + } } \ No newline at end of file From 6fa9abbc418e2395f64ee404a178d53f99367853 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Thu, 26 Jan 2023 14:45:41 +0200 Subject: [PATCH 3/8] fix chrome on m1 --- src/main/java/testUI/AndroidUtils/ADBUtils.java | 14 ++++++++++---- src/main/java/testUI/TestUIServer.java | 2 -- src/test/java/TestRunners/TestAndroidLocal.java | 2 -- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/testUI/AndroidUtils/ADBUtils.java b/src/main/java/testUI/AndroidUtils/ADBUtils.java index a9d56a4..1c28a21 100644 --- a/src/main/java/testUI/AndroidUtils/ADBUtils.java +++ b/src/main/java/testUI/AndroidUtils/ADBUtils.java @@ -380,8 +380,9 @@ private static String getChromedriverVersion(String chromeVersion) { String chromeName = ""; String Platform = System.getProperty("os.name").toLowerCase(); if (Platform.contains("mac")) { + System.out.println(System.getProperty("os.arch")); if (System.getProperty("os.arch").toLowerCase().contains("aarch64")) { - chromeName = "/chromedriver_mac64_m1.zip"; + chromeName = "mac-aarch64"; } else { chromeName = "/chromedriver_mac64.zip"; } @@ -401,8 +402,14 @@ private static String getChromedriverVersion(String chromeVersion) { String text = element.getTextContent(); // Check that the version and platform matches + + if (text.startsWith(version) && chromeName.equals("mac-aarch64")) { + if (text.contains("mac_arm64") || text.contains("m1")) { + chromeDriverVersion = text.split("/")[0]; + } + } if (text.startsWith(version) && text.contains(chromeName)) { - chromeDriverVersion = text.split(chromeName)[0]; + chromeDriverVersion = text.split("/")[0]; } } } @@ -416,8 +423,7 @@ private static Document loadXMLFromString(String xmlString) try { dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); DocumentBuilder builder = dbf.newDocumentBuilder(); - Document doc = builder.parse(new InputSource(new StringReader(xmlString))); - return doc; + return builder.parse(new InputSource(new StringReader(xmlString))); } catch (ParserConfigurationException | IOException | SAXException e) { throw new RuntimeException(e); diff --git a/src/main/java/testUI/TestUIServer.java b/src/main/java/testUI/TestUIServer.java index 2a64710..9e87f37 100644 --- a/src/main/java/testUI/TestUIServer.java +++ b/src/main/java/testUI/TestUIServer.java @@ -390,12 +390,10 @@ public static void stop() { } if (getDevices().size() != 0) { iOSDevices = driver - getDevices().size(); - adbUtils.stopEmulator(getDevices().get(driver - iOSDevices - 1)); removeDevice(driver - iOSDevices - 1); } if (getEmulators().size() != 0) { if ((driver - iOSDevices - 1) < getEmulators().size()) { - adbUtils.stopEmulator(getEmulators().get(driver - iOSDevices - 1)); removeEmulator(driver - iOSDevices - 1); } if ((driver - iOSDevices - 1) < getDevices().size()) { diff --git a/src/test/java/TestRunners/TestAndroidLocal.java b/src/test/java/TestRunners/TestAndroidLocal.java index 7f7c223..ca517d2 100644 --- a/src/test/java/TestRunners/TestAndroidLocal.java +++ b/src/test/java/TestRunners/TestAndroidLocal.java @@ -26,8 +26,6 @@ public void testAndroidBrowser() { googleLandingPage.getGoogleSearchInput().scrollTo().view(true) .given("Check search input visible and set value").waitFor(5) .untilIsVisible(); - googleLandingPage.getGoogleSearch().then("Check that search button visible") - .waitFor(1).untilIsVisible(); stop(); Configuration.testUILogLevel = LogLevel.DEBUG; open("https://www.google.com"); From 987cde933ee55bd7fbf6e513220758adbef75231 Mon Sep 17 00:00:00 2001 From: Alvaro <48132162+alvarolaserna@users.noreply.github.com> Date: Fri, 10 Feb 2023 14:51:59 +0100 Subject: [PATCH 4/8] Update src/main/java/testUI/AndroidUtils/ADBUtils.java Co-authored-by: Alekss Litvinovs <52907932+theRealAlpaca@users.noreply.github.com> --- src/main/java/testUI/AndroidUtils/ADBUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/testUI/AndroidUtils/ADBUtils.java b/src/main/java/testUI/AndroidUtils/ADBUtils.java index 1c28a21..9fabc64 100644 --- a/src/main/java/testUI/AndroidUtils/ADBUtils.java +++ b/src/main/java/testUI/AndroidUtils/ADBUtils.java @@ -429,4 +429,4 @@ private static Document loadXMLFromString(String xmlString) throw new RuntimeException(e); } } -} \ No newline at end of file +} From 12dda0ce7e1225ec448870e9fcd009585249586d Mon Sep 17 00:00:00 2001 From: Alvaro <48132162+alvarolaserna@users.noreply.github.com> Date: Fri, 10 Feb 2023 14:52:08 +0100 Subject: [PATCH 5/8] Update src/main/java/testUI/AndroidUtils/ADBUtils.java Co-authored-by: Alekss Litvinovs <52907932+theRealAlpaca@users.noreply.github.com> --- src/main/java/testUI/AndroidUtils/ADBUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/testUI/AndroidUtils/ADBUtils.java b/src/main/java/testUI/AndroidUtils/ADBUtils.java index 9fabc64..f8c5e5d 100644 --- a/src/main/java/testUI/AndroidUtils/ADBUtils.java +++ b/src/main/java/testUI/AndroidUtils/ADBUtils.java @@ -417,8 +417,7 @@ private static String getChromedriverVersion(String chromeVersion) { return chromeDriverVersion; } - private static Document loadXMLFromString(String xmlString) - { + private static Document loadXMLFromString(String xmlString) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); From 86c9f84a5818386e159c43d75d877e2dd7e5d388 Mon Sep 17 00:00:00 2001 From: Alvaro <48132162+alvarolaserna@users.noreply.github.com> Date: Fri, 10 Feb 2023 14:52:20 +0100 Subject: [PATCH 6/8] Update src/main/java/testUI/AndroidUtils/ADBUtils.java Co-authored-by: Alekss Litvinovs <52907932+theRealAlpaca@users.noreply.github.com> --- src/main/java/testUI/AndroidUtils/ADBUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/testUI/AndroidUtils/ADBUtils.java b/src/main/java/testUI/AndroidUtils/ADBUtils.java index f8c5e5d..98fe58b 100644 --- a/src/main/java/testUI/AndroidUtils/ADBUtils.java +++ b/src/main/java/testUI/AndroidUtils/ADBUtils.java @@ -422,8 +422,8 @@ private static Document loadXMLFromString(String xmlString) { try { dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); DocumentBuilder builder = dbf.newDocumentBuilder(); - return builder.parse(new InputSource(new StringReader(xmlString))); + return builder.parse(new InputSource(new StringReader(xmlString))); } catch (ParserConfigurationException | IOException | SAXException e) { throw new RuntimeException(e); } From 732b5df210f0e87040a77ef0809d65e9f49d5fbe Mon Sep 17 00:00:00 2001 From: Alvaro <48132162+alvarolaserna@users.noreply.github.com> Date: Mon, 13 Feb 2023 10:17:37 +0100 Subject: [PATCH 7/8] Update src/main/java/testUI/AndroidUtils/ADBUtils.java Co-authored-by: Alekss Litvinovs <52907932+theRealAlpaca@users.noreply.github.com> --- src/main/java/testUI/AndroidUtils/ADBUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/testUI/AndroidUtils/ADBUtils.java b/src/main/java/testUI/AndroidUtils/ADBUtils.java index 98fe58b..2c1dbdc 100644 --- a/src/main/java/testUI/AndroidUtils/ADBUtils.java +++ b/src/main/java/testUI/AndroidUtils/ADBUtils.java @@ -400,7 +400,7 @@ private static String getChromedriverVersion(String chromeVersion) { if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; - String text = element.getTextContent(); + String text = element.getElementsByTagName("Key").item(0).getTextContent(); // Check that the version and platform matches if (text.startsWith(version) && chromeName.equals("mac-aarch64")) { From 60a3305d50151e83c764fd5f904bf17752dd7a70 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Mon, 13 Feb 2023 10:27:40 +0100 Subject: [PATCH 8/8] fix comments --- .../java/testUI/AndroidUtils/ADBUtils.java | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/java/testUI/AndroidUtils/ADBUtils.java b/src/main/java/testUI/AndroidUtils/ADBUtils.java index 2c1dbdc..9288969 100644 --- a/src/main/java/testUI/AndroidUtils/ADBUtils.java +++ b/src/main/java/testUI/AndroidUtils/ADBUtils.java @@ -283,10 +283,10 @@ private String returnChromeDriverVersion() { } private String getChromeDriverPath() { - String Platform = System.getProperty("os.name").toLowerCase(); - if (Platform.contains("mac")) { + String platform = System.getProperty("os.name").toLowerCase(); + if (platform.contains("mac")) { return MAC_CHROME_DRIVER; - } else if (Platform.contains("linux")) { + } else if (platform.contains("linux")) { return LNX_CHROME_DRIVER; } else { return getWinNPMPath() + WIN_CHROME_DRIVER; @@ -294,8 +294,8 @@ private String getChromeDriverPath() { } private String getNPMCmd() { - String Platform = System.getProperty("os.name").toLowerCase(); - if (Platform.contains("mac") || Platform.contains("linux")) + String platform = System.getProperty("os.name").toLowerCase(); + if (platform.contains("mac") || platform.contains("linux")) return "npm"; return "npm.cmd"; } @@ -322,8 +322,8 @@ private static String copyFileToCustomFolder(String originalPath, String chromeV ); File targetDir = targetClassesDir.getParentFile(); String destinationPath; - String Platform = System.getProperty("os.name").toLowerCase(); - if (Platform.contains("mac") || Platform.contains("linux")) { + String platform = System.getProperty("os.name").toLowerCase(); + if (platform.contains("mac") || platform.contains("linux")) { destinationPath = targetDir + "/chromedriver" + chromeVersion; } else { destinationPath = targetDir + "\\chromedriver" + chromeVersion + ".exe"; @@ -345,8 +345,8 @@ private static boolean getTargetDirectory(TestUIConfiguration configuration, ); File targetDir = targetClassesDir.getParentFile(); String destinationPath; - String Platform = System.getProperty("os.name").toLowerCase(); - if (Platform.contains("mac") || Platform.contains("linux")) { + String platform = System.getProperty("os.name").toLowerCase(); + if (platform.contains("mac") || platform.contains("linux")) { destinationPath = targetDir + "/chromedriver" + chromeVersion; } else { destinationPath = targetDir + "\\chromedriver" + chromeVersion + ".exe"; @@ -378,18 +378,19 @@ private static String getChromedriverVersion(String chromeVersion) { } String chromeDriverVersion = ""; String chromeName = ""; - String Platform = System.getProperty("os.name").toLowerCase(); - if (Platform.contains("mac")) { - System.out.println(System.getProperty("os.arch")); + String platform = System.getProperty("os.name").toLowerCase(); + if (platform.contains("mac")) { if (System.getProperty("os.arch").toLowerCase().contains("aarch64")) { chromeName = "mac-aarch64"; } else { chromeName = "/chromedriver_mac64.zip"; } - } else if (Platform.contains("linux")) { + } else if (platform.contains("linux")) { chromeName = "/chromedriver_linux64.zip"; - } else { + } else if (platform.contains("win")) { chromeName = "/chromedriver_win32.zip"; + } else { + throw new TestUIException("Platform is not included within chromedriver downloads"); } Document doc = loadXMLFromString(body); // Getting each of the chrome driver versions from the chromium api @@ -397,21 +398,22 @@ private static String getChromedriverVersion(String chromeVersion) { for (int temp = 0; temp < list.getLength(); temp++) { Node node = list.item(temp); - if (node.getNodeType() == Node.ELEMENT_NODE) { - Element element = (Element) node; + if (node.getNodeType() != Node.ELEMENT_NODE) { + continue; + } + Element element = (Element) node; - String text = element.getElementsByTagName("Key").item(0).getTextContent(); - // Check that the version and platform matches + String text = element.getElementsByTagName("Key").item(0).getTextContent(); + // Check that the version and platform matches - if (text.startsWith(version) && chromeName.equals("mac-aarch64")) { - if (text.contains("mac_arm64") || text.contains("m1")) { - chromeDriverVersion = text.split("/")[0]; - } - } - if (text.startsWith(version) && text.contains(chromeName)) { + if (text.startsWith(version) && chromeName.equals("mac-aarch64")) { + if (text.contains("mac_arm64") || text.contains("m1")) { chromeDriverVersion = text.split("/")[0]; } } + if (text.startsWith(version) && text.contains(chromeName)) { + chromeDriverVersion = text.split("/")[0]; + } } return chromeDriverVersion;