From ef5d4430db75740d7751ae32e41ae5220694be48 Mon Sep 17 00:00:00 2001 From: Uladzislau Arlouski Date: Sat, 26 Jun 2021 21:27:24 +0300 Subject: [PATCH] Add ability to get web url for automated test --- .../crossbrowsertesting/AutomatedTest.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/crossbrowsertesting/AutomatedTest.java b/src/main/java/com/crossbrowsertesting/AutomatedTest.java index 3000162..5e8c253 100644 --- a/src/main/java/com/crossbrowsertesting/AutomatedTest.java +++ b/src/main/java/com/crossbrowsertesting/AutomatedTest.java @@ -8,6 +8,7 @@ +import com.mashape.unirest.request.GetRequest; import org.apache.commons.codec.binary.Base64; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; @@ -94,9 +95,7 @@ public Snapshot takeSnapshot(String description) throws UnirestException {//over public Snapshot[] getSnapshots() throws UnirestException { Snapshot[] snaps; - HttpResponse response = Unirest.get(Builders.api + this.testId + "/snapshots") - .basicAuth(Builders.username, Builders.authkey) - .asString(); + HttpResponse response = doGet("/snapshots").asString(); JSONArray results = new JSONArray(response.getBody()); String hash; snaps = new Snapshot[results.length()]; @@ -118,9 +117,7 @@ public Video startRecordingVideo() throws UnirestException { public Video[] getVideos() throws UnirestException { Video[] videos; - HttpResponse response = Unirest.get(Builders.api + this.testId + "/videos") - .basicAuth(Builders.username, Builders.authkey) - .asString(); + HttpResponse response = doGet("/videos").asString(); JSONArray results = new JSONArray(response.getBody()); String hash; videos = new Video[results.length()]; @@ -169,4 +166,16 @@ public void saveAllVideos(String directory, boolean useDescription) throws Unire count++; } } -} \ No newline at end of file + + public String getWebUrl() throws UnirestException { + return doGet("").asJson() + .getBody() + .getObject() + .getString("show_result_web_url"); + } + + private GetRequest doGet(String relativeUrl) { + return Unirest.get(Builders.api + this.testId + relativeUrl) + .basicAuth(Builders.username, Builders.authkey); + } +}