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
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ private void performDriverChecks() throws BadJsonFormatException {
continue;
}
if (!expectedDriverCaps.getCapabilityNames().contains("app")) {
ApplauseAppPushHelper.performApplicationPushIfNecessary();
ApplauseAppPushHelper.autoDetectBuildIfNecessary();
ApplauseAppPushHelper.performApplicationPushIfNecessary();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.Map;
import java.util.Optional;
import lombok.NonNull;
import okhttp3.MediaType;
import okhttp3.Response;
import okhttp3.ResponseBody;

Expand Down Expand Up @@ -198,15 +197,6 @@ public static JsonObject httpRspToJsonObject(@NonNull final Response okHttpRsp)
if (body == null) {
throw new RuntimeException("Unable to parse response - null body");
}
// IF the context type is not passed back correctly, then default it to application json
MediaType contentAndMetaData =
Optional.ofNullable(body.contentType()).orElse(MediaType.get("application/json"));
if (!"json".equalsIgnoreCase(contentAndMetaData.subtype())) {
throw new RuntimeException(
String.format(
"Non JSON content: type=%s, subtype=%s",
contentAndMetaData.type(), contentAndMetaData.subtype()));
}
final String rawBody;
try {
rawBody = body.string();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Base64;
import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.HttpMethod;
Expand Down Expand Up @@ -304,10 +305,10 @@ static String createErrMsg(
*/
public static String pushProviderToPushAppClass(@NonNull final String pushProvider) {
// Eventually we should externalize this
if ("BROWSERSTACK".equalsIgnoreCase(pushProvider)) {
if (pushProvider.toUpperCase(Locale.getDefault()).contains("BROWSERSTACK")) {
return BrowserstackPusher.class.getCanonicalName();
}
if ("SAUCELABS".equalsIgnoreCase(pushProvider)) {
if (pushProvider.toUpperCase(Locale.getDefault()).contains("SAUCELABS")) {
return SauceLabsPusher.class.getCanonicalName();
}
throw new RuntimeException("Unable to map " + pushProvider + " to a concrete class");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.util.Optional;
import lombok.NonNull;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

/** An Application Push implementation for SauceLabs */
Expand All @@ -43,9 +49,22 @@ public SauceLabsPusher() {
@Override
public RequestBody getRequestBody() {
File fileToPush = getFileToPush();

// If we don't have a file to push, we will need to fetch the app from the provided url as
// SauceLabs does not support pushing
// URLs directly. This is a workaround for the fact that SauceLabs does not support pushing
// URLs directly.
if (fileToPush == null) {
throw new RuntimeException(
"SauceLabs does not support pushing remote urls to app storage. Use the 'app' capability to supply remote urls");
try {
URL url = new URI(getUrlToPush()).toURL();
final var pathTokens = url.getPath().split("/");
final var fileName = pathTokens[pathTokens.length - 1];
fileToPush = Files.createTempFile(null, fileName).toFile();
FileUtils.copyURLToFile(url, fileToPush);
} catch (IOException | URISyntaxException e) {
throw new RuntimeException(
"Unable to download app file for SauceLabs upload. Please check your permissions.", e);
}
}
return new MultipartBody.Builder()
.setType(MultipartBody.FORM)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ private void performDriverChecks(final ISuite suite) throws BadJsonFormatExcepti
continue;
}
if (!expectedDriverCaps.getCapabilityNames().contains("app")) {
ApplauseAppPushHelper.performApplicationPushIfNecessary();
ApplauseAppPushHelper.autoDetectBuildIfNecessary();
ApplauseAppPushHelper.performApplicationPushIfNecessary();
break;
}
}
Expand Down