Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support to run test on genymotion (#515)
* support to run test on genymotion * fix azure yaml * add GM caps * add server path to azure * improved logging * make codacy happy
- Loading branch information
1 parent
cc1e6b4
commit bb8d57c
Showing
10 changed files
with
225 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"android": { | ||
"automationName": "UIAutomator2", | ||
"project": "ATD", | ||
"app": { | ||
"local": "https://github.com/shridharkalagi/AppiumSample/raw/master/VodQA.apk" | ||
}, | ||
"noSign": true | ||
}, | ||
"genycloud": { | ||
"android": [ | ||
{ | ||
"udid": "107d757e-463a-4a18-8667-b8dec6e4c87e", | ||
"deviceName": "Google Pixel", | ||
"osVersion": "9.0" | ||
}, | ||
{ | ||
"udid": "a59951f2-ed13-40f9-80b9-3ddceb3c89f5", | ||
"deviceName": "Google Nexus 6", | ||
"osVersion": "8.0" | ||
} | ||
] | ||
}, | ||
"hostMachines": [ | ||
{ | ||
"machineIP": "127.0.0.1", | ||
"appiumServerPath": "/usr/local/lib/node_modules/appium/build/lib/main.js" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
RUNNER=distribute | ||
FRAMEWORK=testng | ||
CAPS=./caps/genymotion.json | ||
RUNNER_LEVEL=methods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.appium.device; | ||
|
||
import com.appium.utils.Api; | ||
import com.appium.utils.CommandPrompt; | ||
import okhttp3.Response; | ||
import org.json.simple.JSONArray; | ||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
import org.json.simple.parser.ParseException; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.logging.Logger; | ||
|
||
public class GenyMotionManager { | ||
|
||
private static final Logger LOGGER = Logger | ||
.getLogger(GenyMotionManager.class.getSimpleName()); | ||
private static String cloud_user = System.getenv("CLOUD_USER"); | ||
private static String cloud_key = System.getenv("CLOUD_KEY"); | ||
|
||
protected static void connectToGenyCloud(String udid, Object devices) throws IOException { | ||
|
||
String gmLogin = "gmsaas auth login " | ||
+ cloud_user + " " + cloud_key; | ||
try { | ||
new CommandPrompt() | ||
.runCommandThruProcess(gmLogin); | ||
LOGGER.info("Connected to Genymotion Cloud.."); | ||
} catch (IOException e) { | ||
throw new IOException("Failed to Connect to geny cloud.."); | ||
} | ||
|
||
((ArrayList)devices).parallelStream().forEach(o -> { | ||
|
||
String instanceUdid = (String) ((HashMap) o).get("udid"); | ||
String instanceName = (String) ((HashMap) o).get("deviceName"); | ||
String gnInstance = "gmsaas instances start " | ||
+ instanceUdid + " " + "\"" + instanceName + "\""; | ||
LOGGER.info("Starting Device on genymotion cloud instance with uuid" | ||
+ instanceUdid + "and device name " + instanceName); | ||
String createdInstance; | ||
try { | ||
createdInstance = new CommandPrompt() | ||
.runCommandThruProcess(gnInstance); | ||
String adbTunnel = "gmsaas instances adbconnect " | ||
+ " " + createdInstance; | ||
new CommandPrompt() | ||
.runCommandThruProcess(adbTunnel); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
}); | ||
|
||
try { | ||
LOGGER.info("Running Instances"); | ||
String gmsaas_instances_list = new CommandPrompt() | ||
.runCommandThruProcess("gmsaas instances list"); | ||
LOGGER.info(gmsaas_instances_list); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
public void stopAllGenymotionInstances() throws ParseException, IOException { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("email", cloud_user); | ||
jsonObject.put("password", cloud_key); | ||
Api api = new Api(); | ||
String post = api.post("https://api.geny.io/cloud/v1/users/login", jsonObject.toString()); | ||
JSONParser parser = new JSONParser(); | ||
Object parse = parser.parse(post); | ||
Object token = ((JSONObject) parse).get("token"); | ||
Response response = api.requestBuilderWithBearerToken("https://api.geny.io/cloud/v1/instances", token.toString()); | ||
String string = response.body().string(); | ||
JSONParser responseUdid = new JSONParser(); | ||
((JSONArray) responseUdid.parse(string)).parallelStream().forEach(o -> { | ||
Object uuid = ((JSONObject) o).get("uuid"); | ||
LOGGER.info("Stopping Genymotion instance.." + uuid.toString()); | ||
String recipe_uuid = null; | ||
recipe_uuid = api.postWithNoBody("https://api.geny.io/cloud/v1/instances/" + uuid | ||
+ "/stop-disposable", token.toString()); | ||
System.out.println(recipe_uuid); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters