Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 71 additions & 22 deletions src/main/java/testUI/AndroidUtils/ADBUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -276,19 +283,19 @@ 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;
}
}

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";
}
Expand All @@ -315,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";
Expand All @@ -338,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";
Expand Down Expand Up @@ -369,16 +376,58 @@ 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)) {
if (text.contains("/chromedriver_mac64.zip")) {
new_chrome_version =
version + text.split("/chromedriver_mac64\\.zip")[0];
String chromeDriverVersion = "";
String chromeName = "";
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")) {
chromeName = "/chromedriver_linux64.zip";
} 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
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) {
continue;
}
Element element = (Element) node;

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)) {
chromeDriverVersion = text.split("/")[0];
}
if (new_chrome_version.length() < 17)
chromeDriverVersion = new_chrome_version;
}

return chromeDriverVersion;
}
}

private static Document loadXMLFromString(String xmlString) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
DocumentBuilder builder = dbf.newDocumentBuilder();

return builder.parse(new InputSource(new StringReader(xmlString)));
} catch (ParserConfigurationException | IOException | SAXException e) {
throw new RuntimeException(e);
}
}
}
2 changes: 0 additions & 2 deletions src/main/java/testUI/TestUIServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/TestRunners/TestAndroidLocal.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down