Skip to content

Commit

Permalink
#593: backport powermock deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
bhecquet committed Feb 14, 2024
1 parent be459c0 commit cb69080
Show file tree
Hide file tree
Showing 146 changed files with 5,568 additions and 5,233 deletions.
45 changes: 23 additions & 22 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<dependency>
<groupId>com.deque.html.axe-core</groupId>
<artifactId>selenium</artifactId>
<version>4.7.0</version>
<version>4.8.0</version>
</dependency>
<dependency>
<groupId>com.eatthepath</groupId>
Expand Down Expand Up @@ -93,7 +93,7 @@
<artifactId>java-client</artifactId>
</dependency>
<dependency>
<groupId>com.vdurmont</groupId>
<groupId>org.semver4j</groupId>
<artifactId>semver4j</artifactId>
</dependency>
<dependency>
Expand Down Expand Up @@ -170,8 +170,8 @@
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
<artifactId>jakarta.mail</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
Expand Down Expand Up @@ -309,26 +309,27 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.12.4</version>
<artifactId>mockito-inline</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>jetty-repacked</artifactId>
<version>9.4.12.v20180830.1</version>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-testng</artifactId>
<version>0.5.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.45.v20220203</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.45.v20220203</version>
<scope>test</scope>
</dependency>
<!-- needed for offline instrumentation. Offline is used because tests using powermockito are not correctly analyzed due to https://github.com/powermock/powermock/issues/727 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
*/
package com.seleniumtests.browserfactory;

import io.appium.java_client.android.options.UiAutomator2Options;
import org.openqa.selenium.MutableCapabilities;

import com.seleniumtests.driver.BrowserType;
import com.seleniumtests.driver.DriverConfig;

import io.appium.java_client.remote.AndroidMobileCapabilityType;

/**
* Sets Android capabilities.
*/
Expand All @@ -35,33 +34,30 @@ public AndroidCapabilitiesFactory(DriverConfig webDriverConfig) {

@Override
protected String getAutomationName() {
if (webDriverConfig.getMobilePlatformVersion() != null && Integer.parseInt(webDriverConfig.getMobilePlatformVersion().split("\\.")[0]) < 4) {
return "Selendroid";
} else if (webDriverConfig.getMobilePlatformVersion() != null && Integer.parseInt(webDriverConfig.getMobilePlatformVersion().split("\\.")[0]) < 6) {
return "UiAutomator1";
} else if (webDriverConfig.getAutomationName() == null) {
return "Appium";
if (webDriverConfig.getAutomationName() == null) {
return "UiAutomator2";
} else {
return webDriverConfig.getAutomationName();
}
}

@Override
protected MutableCapabilities getSystemSpecificCapabilities() {
MutableCapabilities capabilities = new MutableCapabilities();


// automatically hide keyboard
// capabilities.setCapability(AndroidMobileCapabilityType.RESET_KEYBOARD, true);
// capabilities.setCapability(AndroidMobileCapabilityType.UNICODE_KEYBOARD, true);

capabilities.setCapability(SeleniumRobotCapabilityType.APPIUM_PREFIX + AndroidMobileCapabilityType.APP_PACKAGE, webDriverConfig.getAppPackage());
capabilities.setCapability(SeleniumRobotCapabilityType.APPIUM_PREFIX + AndroidMobileCapabilityType.APP_ACTIVITY, webDriverConfig.getAppActivity());

UiAutomator2Options options = new UiAutomator2Options()
.setAppPackage(webDriverConfig.getAppPackage())
.setAppActivity(webDriverConfig.getAppActivity())
.setDeviceName(webDriverConfig.getDeviceName());

if (webDriverConfig.getAppWaitActivity() != null) {
capabilities.setCapability(SeleniumRobotCapabilityType.APPIUM_PREFIX + AndroidMobileCapabilityType.APP_WAIT_ACTIVITY, webDriverConfig.getAppWaitActivity());
options.setAppWaitActivity(webDriverConfig.getAppWaitActivity());
}

return capabilities;
return options;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Optional;

import io.appium.java_client.android.options.UiAutomator2Options;
import io.appium.java_client.ios.options.XCUITestOptions;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
Expand All @@ -36,9 +39,6 @@

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.IOSMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;

public class AppiumDriverFactory extends AbstractWebDriverFactory implements IWebDriverFactory {

Expand All @@ -50,12 +50,12 @@ public AppiumDriverFactory(final DriverConfig cfg) {
}

private void extractAndroidDriver(MutableCapabilities capabilities) {
String chromeDriverFile = (String)capabilities.getCapability(SeleniumRobotCapabilityType.APPIUM_PREFIX + AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE);
if (chromeDriverFile != null) {
Optional<String> chromeDriverFile = ((UiAutomator2Options)capabilities).getChromedriverExecutable();
if (chromeDriverFile.isPresent() && chromeDriverFile.get() != null) {
String driverPath;
try {
driverPath = FileUtility.decodePath(new DriverExtractor().extractDriver(chromeDriverFile));
capabilities.setCapability(SeleniumRobotCapabilityType.APPIUM_PREFIX + AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE, driverPath);
driverPath = FileUtility.decodePath(new DriverExtractor().extractDriver(chromeDriverFile.get()));
((UiAutomator2Options)capabilities).setChromedriverExecutable(driverPath);
} catch (UnsupportedEncodingException e) {
logger.error("cannot get driver path", e);
}
Expand Down Expand Up @@ -103,10 +103,17 @@ private MutableCapabilities getMobileCapabilities() {
}

if (capabilities.getCapability(CapabilityType.PLATFORM_NAME).toString().equalsIgnoreCase(ANDROID_PLATORM)) {
capabilities.setCapability(SeleniumRobotCapabilityType.APPIUM_PREFIX + MobileCapabilityType.DEVICE_NAME, webDriverConfig.getDeviceId());
UiAutomator2Options androidCaps = new UiAutomator2Options(capabilities);
androidCaps.setDeviceName(webDriverConfig.getDeviceId());

return androidCaps;
} else { // iOS
capabilities.setCapability(SeleniumRobotCapabilityType.APPIUM_PREFIX + IOSMobileCapabilityType.XCODE_CONFIG_FILE, (String)null); // remove this capability as it may not be accurate
capabilities.setCapability(SeleniumRobotCapabilityType.APPIUM_PREFIX + MobileCapabilityType.UDID, webDriverConfig.getDeviceId());
XCUITestOptions iosCaps = new XCUITestOptions(capabilities);
iosCaps.setUdid(webDriverConfig.getDeviceId());

return iosCaps;
//capabilities.setCapability(SeleniumRobotCapabilityType.APPIUM_PREFIX + IOSMobileCapabilityType.XCODE_CONFIG_FILE, (String)null); // remove this capability as it may not be accurate

}
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void addDriverFile() throws IOException {
checkResourceExists();
}

private void checkResourceExists() {
public void checkResourceExists() {
if (driverFileName != null && getClass().getClassLoader()
.getResourceAsStream(String.format("drivers/%s/%s%s", os, driverFileName, OSUtilityFactory.getInstance().getProgramExtension())) == null) {
throw new ConfigurationException(String.format("Driver file %s does not exist in resources", driverFileName));
Expand Down Expand Up @@ -500,6 +500,7 @@ public static List<String> getDriverList() {
return driverList;
}

// for tests only
public static void setDriverList(List<String> driverList) {
BrowserInfo.driverList = driverList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@

import java.io.File;
import java.io.IOException;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import io.appium.java_client.android.options.UiAutomator2Options;
import org.apache.http.auth.AuthenticationException;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.seleniumtests.core.SeleniumTestsContextManager;
import com.seleniumtests.customexception.ConfigurationException;
import com.seleniumtests.driver.DriverConfig;

import io.appium.java_client.remote.MobileCapabilityType;
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
Expand All @@ -48,9 +50,9 @@ public BrowserStackCapabilitiesFactory(DriverConfig webDriverConfig) {


@Override
public DesiredCapabilities createCapabilities() {
public MutableCapabilities createCapabilities() {

final DesiredCapabilities capabilities = new DesiredCapabilities();
final MutableCapabilities capabilities = new DesiredCapabilities();

// platform must be the concatenation of 'os' and 'os_version' that browserstack undestands
String platform = webDriverConfig.getPlatform();
Expand All @@ -63,7 +65,7 @@ public DesiredCapabilities createCapabilities() {
Capabilities androidCaps = new AndroidCapabilitiesFactory(webDriverConfig).createCapabilities();
capabilities.merge(androidCaps);

capabilities.setCapability(SeleniumRobotCapabilityType.APPIUM_PREFIX + MobileCapabilityType.AUTOMATION_NAME, "UIAutomator2");
((UiAutomator2Options)capabilities).setAutomationName("UIAutomator2");

} else if (IOS_PLATFORM.equalsIgnoreCase(webDriverConfig.getPlatform())){
Capabilities iosCaps = new IOsCapabilitiesFactory(webDriverConfig).createCapabilities();
Expand Down Expand Up @@ -100,19 +102,18 @@ public DesiredCapabilities createCapabilities() {
capabilities.setCapability("project", SeleniumTestsContextManager.getApplicationName());

// we need to upload something
if (capabilities.getCapability(SeleniumRobotCapabilityType.APPIUM_PREFIX + MobileCapabilityType.APP) != null) {
String appUrl = uploadFile((String)capabilities.getCapability(SeleniumRobotCapabilityType.APPIUM_PREFIX + MobileCapabilityType.APP));
Optional<String> applicationOption = getApp(capabilities);
if (applicationOption.isPresent() && applicationOption.get() != null) {
String appUrl = uploadFile(applicationOption.get());
capabilities.setCapability("app", appUrl);

}

return capabilities;

// be sure not to have appium capabilities so that further setCapabilities do not add "appium:" prefix
return new MutableCapabilities(capabilities);
}

/**
* Upload application to saucelabs server
* @param targetAppPath
* @param serverURL
* Upload application to browserstack server
* @return
* @throws IOException
* @throws AuthenticationException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.logging.Level;
import java.util.stream.Collectors;

import io.appium.java_client.android.options.UiAutomator2Options;
import io.appium.java_client.android.options.context.SupportsChromedriverExecutableOption;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
Expand All @@ -36,11 +38,6 @@
import com.seleniumtests.driver.DriverMode;
import com.seleniumtests.util.logging.DebugMode;

import io.appium.java_client.remote.AndroidMobileCapabilityType;

/**
* See common flags: https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md
*/
public class ChromeCapabilitiesFactory extends IDesktopCapabilityFactory {

private static final String USER_DATA_DIR_OPTION = "--user-data-dir=";
Expand All @@ -52,8 +49,8 @@ public ChromeCapabilitiesFactory(DriverConfig webDriverConfig) {
/**
* Create capabilities for mobile chrome
*/
public DesiredCapabilities createMobileCapabilities(final DriverConfig webDriverConfig) {
DesiredCapabilities capabilities = new DesiredCapabilities();
public MutableCapabilities createMobileCapabilities(final DriverConfig webDriverConfig) {
UiAutomator2Options capabilities = new UiAutomator2Options();
ChromeOptions options = new ChromeOptions();
if (webDriverConfig.getUserAgentOverride() != null) {
options.addArguments("--user-agent=" + webDriverConfig.getUserAgentOverride());
Expand All @@ -76,17 +73,17 @@ public DesiredCapabilities createMobileCapabilities(final DriverConfig webDriver
capabilities.setCapability(ChromeOptions.CAPABILITY, options);

// TEST_MOBILE
capabilities.setCapability(AndroidMobileCapabilityType.NATIVE_WEB_SCREENSHOT, true);
capabilities.setNativeWebScreenshot(true);
// TEST_MOBILE

if (webDriverConfig.getMode() == DriverMode.LOCAL) {
capabilities.setCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE, System.getProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY));
capabilities.setChromedriverExecutable(System.getProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY));

// driver logging
setLogging();
}

return capabilities;
return new MutableCapabilities(capabilities);
}

private void setLogging() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,49 @@
*/
package com.seleniumtests.browserfactory;

import io.appium.java_client.android.options.UiAutomator2Options;
import io.appium.java_client.ios.options.XCUITestOptions;
import io.appium.java_client.remote.options.BaseOptions;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.MutableCapabilities;

import com.seleniumtests.driver.DriverConfig;
import com.seleniumtests.util.logging.SeleniumRobotLogger;
import org.openqa.selenium.Platform;

import java.util.Optional;

public abstract class ICapabilitiesFactory {

protected static final Logger logger = SeleniumRobotLogger.getLogger(ICapabilitiesFactory.class);

/**
* returns the app in capabilities
* @param caps
* @return
*/
protected Optional<String> getApp(Capabilities caps) {

if (new BaseOptions(caps).getPlatformName() == null) {
return Optional.empty();
} else if (new BaseOptions(caps).getPlatformName().is(Platform.ANDROID)) {
return new UiAutomator2Options(caps).getApp();
} else if (new BaseOptions(caps).getPlatformName().is(Platform.IOS)) {
return new XCUITestOptions(caps).getApp();
} else return Optional.empty();
}

protected Capabilities setApp(Capabilities caps, String app) {
if (new BaseOptions(caps).getPlatformName().is(Platform.ANDROID)) {
return new UiAutomator2Options(caps).setApp(app);
} else if (new BaseOptions(caps).getPlatformName().is(Platform.IOS)) {
return new XCUITestOptions(caps).setApp(app);
} else {
return caps;
}
}

protected DriverConfig webDriverConfig;

protected ICapabilitiesFactory(DriverConfig webDriverConfig) {
Expand Down
Loading

0 comments on commit cb69080

Please sign in to comment.