Skip to content

Commit dc619d1

Browse files
committed
changes for app automation capability service & report
1 parent 0951150 commit dc619d1

File tree

24 files changed

+1253
-23
lines changed

24 files changed

+1253
-23
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ plugins {
3030

3131
group = 'org.jenkins-ci.plugins'
3232

33-
version = '1.20.5'
33+
version = '1.20.6'
3434

3535
description = 'LambdaTest Plugin is used to run automated selenium tests on LambdaTest Cloud'
3636

src/main/java/com/lambdatest/jenkins/credential/MagicPlugCredentialsImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.util.Collections;
55
import java.util.List;
6+
import java.util.logging.Logger;
67

78
import javax.annotation.CheckForNull;
89
import javax.annotation.Nullable;
@@ -32,15 +33,15 @@ public class MagicPlugCredentialsImpl extends BaseStandardCredentials implements
3233
private final String userName;
3334
private final Secret accessToken;
3435

36+
private static final Logger logger = Logger.getLogger(MagicPlugCredentialsImpl.class.getName());
37+
3538
@DataBoundConstructor
3639
public MagicPlugCredentialsImpl(CredentialsScope scope, String id, String description, String userName,
3740
String accessToken) throws Exception {
3841
super(scope, id, description);
3942
try {
40-
System.out.println("MagicPlugCredentialsImpl");
4143
this.userName = userName;
4244
this.accessToken = Secret.fromString(accessToken);
43-
System.out.println("Here We can Verify Credentials Also before Adding");
4445
if (!CapabilityService.isValidUser(userName, accessToken)) {
4546
throw new Exception("Invalid username and access Token");
4647
}
@@ -82,7 +83,7 @@ public String getCredentialsPage() {
8283

8384
public FormValidation doVerifyCredentials(@QueryParameter("userName") final String userName,
8485
@QueryParameter("accessToken") final String accessToken) throws IOException, ServletException {
85-
System.out.println(userName + ":" + accessToken);
86+
logger.info(userName + ":" + accessToken);
8687
if (StringUtils.isBlank(userName) || StringUtils.isBlank(accessToken)) {
8788
return FormValidation.error("Please enter valid username and authKey");
8889
}

src/main/java/com/lambdatest/jenkins/freestyle/MagicPlugBuildWrapper.java

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.lambdatest.jenkins.freestyle.api.Constant;
2626
import com.lambdatest.jenkins.freestyle.api.auth.UserAuthResponse;
2727
import com.lambdatest.jenkins.freestyle.api.service.CapabilityService;
28+
import com.lambdatest.jenkins.freestyle.api.service.AppAutomationCapabilityService;
2829
import com.lambdatest.jenkins.freestyle.data.LocalTunnel;
2930
import com.lambdatest.jenkins.freestyle.service.LambdaTunnelService;
3031
import com.lambdatest.jenkins.freestyle.service.LambdaWebSocketTunnelService;
@@ -43,6 +44,8 @@
4344
public class MagicPlugBuildWrapper extends BuildWrapper implements Serializable {
4445

4546
private List<JSONObject> seleniumCapabilityRequest;
47+
private List<JSONObject> appAutomationCapabilityRequest;
48+
private String appId;
4649
private String credentialsId;
4750
private String username;
4851
private Secret accessToken;
@@ -65,7 +68,7 @@ public class MagicPlugBuildWrapper extends BuildWrapper implements Serializable
6568
private static final Logger logger = Logger.getLogger(MagicPlugBuildWrapper.class.getName());
6669

6770
@DataBoundConstructor
68-
public MagicPlugBuildWrapper(StaplerRequest req, @CheckForNull List<JSONObject> seleniumCapabilityRequest,
71+
public MagicPlugBuildWrapper(StaplerRequest req, @CheckForNull List<JSONObject> seleniumCapabilityRequest, @CheckForNull List<JSONObject> appAutomationCapabilityRequest,
6972
@CheckForNull String credentialsId, String choice, boolean useLocalTunnel, LocalTunnel localTunnel,
7073
ItemGroup context) throws Exception {
7174
try {
@@ -77,6 +80,13 @@ public MagicPlugBuildWrapper(StaplerRequest req, @CheckForNull List<JSONObject>
7780
validateTestInput(seleniumCapabilityRequest);
7881
this.seleniumCapabilityRequest = seleniumCapabilityRequest;
7982
}
83+
if (appAutomationCapabilityRequest == null) {
84+
// prevent null pointer
85+
this.appAutomationCapabilityRequest = new ArrayList<JSONObject>();
86+
} else {
87+
validateTestInput(appAutomationCapabilityRequest);
88+
this.appAutomationCapabilityRequest = appAutomationCapabilityRequest;
89+
}
8090
// Setting up credentials in both case if input capabilities are there or not
8191
this.choice = choice;
8292
setLambdaTestCredentials(credentialsId, context);
@@ -160,8 +170,14 @@ public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener l
160170
}
161171

162172
// Create Grid URL
163-
this.gridURL = CapabilityService.buildHubURL(this.username, this.accessToken.getPlainText(),"production");
173+
if (!CollectionUtils.isEmpty(seleniumCapabilityRequest)) {
174+
this.gridURL = CapabilityService.buildHubURL(this.username, this.accessToken.getPlainText(),"production");
164175
logger.info(this.gridURL);
176+
} else if (!CollectionUtils.isEmpty(appAutomationCapabilityRequest)) {
177+
logger.info("appAutomationCR : " + appAutomationCapabilityRequest);
178+
this.gridURL = AppAutomationCapabilityService.appAutomationBuildHubURL(this.username, this.accessToken.getPlainText(),"production");
179+
}
180+
logger.info("grid URL : " + this.gridURL);
165181
return new MagicPlugEnvironment(build);
166182
}
167183

@@ -207,7 +223,17 @@ public void buildEnvVars(Map<String, String> env) {
207223
env.put(Constant.LT_BROWSER_VERSION, seleniumCapability.getString(Constant.BROWSER_VERSION));
208224
env.put(Constant.LT_RESOLUTION, seleniumCapability.getString(Constant.RESOLUTION));
209225
}
226+
if (!CollectionUtils.isEmpty(appAutomationCapabilityRequest)) {
227+
JSONObject appAutomationCapability = appAutomationCapabilityRequest.get(0);
228+
env.put(Constant.LT_PLATFORM_NAME, appAutomationCapability.getString(Constant.PLATFORM_NAME));
229+
env.put(Constant.LT_BRAND_NAME, appAutomationCapability.getString(Constant.BRAND_NAME));
230+
env.put(Constant.LT_DEVICE_NAME, appAutomationCapability.getString(Constant.DEVICE_NAME));
231+
env.put(Constant.LT_DEVICE_VERSION, appAutomationCapability.getString(Constant.DEVICE_VERSION));
232+
env.put(Constant.LT_APP_ID, appAutomationCapability.getString(Constant.APP_ID));
233+
}
210234
env.put(Constant.LT_BROWSERS, createBrowserJSON(seleniumCapabilityRequest));
235+
env.put(Constant.LT_BRANDS, createBrandJSON(appAutomationCapabilityRequest));
236+
env.put(Constant.LT_DEVICES, createDeviceJSON(appAutomationCapabilityRequest));
211237
env.put(Constant.LT_GRID_URL, gridURL);
212238
env.put(Constant.LT_BUILD_NAME, buildname);
213239
env.put(Constant.LT_BUILD_NUMBER, buildnumber);
@@ -246,6 +272,30 @@ private String createBrowserJSON(List<JSONObject> seleniumCapabilityRequests) {
246272
}
247273
return config;
248274
}
275+
private String createDeviceJSON(List<JSONObject> appAutomationCapabilityRequests) {
276+
String config = Constant.NOT_AVAILABLE;
277+
try {
278+
ObjectMapper objectMapper = new ObjectMapper();
279+
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
280+
config = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(appAutomationCapabilityRequests);
281+
} catch (JsonProcessingException e) {
282+
logger.warning(e.getMessage());
283+
}
284+
return config;
285+
}
286+
287+
private String createBrandJSON(List<JSONObject> appAutomationCapabilityRequests) {
288+
String config = Constant.NOT_AVAILABLE;
289+
try {
290+
ObjectMapper objectMapper = new ObjectMapper();
291+
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
292+
config = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(appAutomationCapabilityRequests);
293+
} catch (JsonProcessingException e) {
294+
logger.warning(e.getMessage());
295+
}
296+
return config;
297+
}
298+
249299

250300
@Override
251301
public boolean tearDown(AbstractBuild build, BuildListener listener) throws IOException, InterruptedException {
@@ -320,6 +370,21 @@ public List<JSONObject> getSeleniumCapabilityRequest() {
320370
public void setSeleniumCapabilityRequest(List<JSONObject> seleniumCapabilityRequest) {
321371
this.seleniumCapabilityRequest = seleniumCapabilityRequest;
322372
}
373+
public List<JSONObject> getAppAutomationCapabilityRequest() {
374+
return appAutomationCapabilityRequest;
375+
}
376+
377+
public void setAppAutomationCapabilityRequest(List<JSONObject> appAutomationCapabilityRequest) {
378+
this.appAutomationCapabilityRequest = appAutomationCapabilityRequest;
379+
}
380+
381+
public String getAppId() {
382+
return appId;
383+
}
384+
385+
public void setAppid(String appId) {
386+
this.appId = appId;
387+
}
323388

324389
public String getUsername() {
325390
return username;

src/main/java/com/lambdatest/jenkins/freestyle/MagicPlugDescriptor.java

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.List;
55
import java.util.Map;
66
import java.util.Set;
7+
import java.util.logging.Logger;
78

89
import javax.servlet.ServletException;
910

@@ -16,6 +17,8 @@
1617
import com.lambdatest.jenkins.credential.MagicPlugCredentialsImpl;
1718
import com.lambdatest.jenkins.freestyle.api.Constant;
1819
import com.lambdatest.jenkins.freestyle.api.service.CapabilityService;
20+
import com.lambdatest.jenkins.freestyle.data.AppAutomationCapabilityRequest;
21+
import com.lambdatest.jenkins.freestyle.api.service.AppAutomationCapabilityService;
1922

2023
import hudson.Extension;
2124
import hudson.model.AbstractProject;
@@ -27,6 +30,8 @@
2730
@Extension
2831
public class MagicPlugDescriptor extends BuildWrapperDescriptor {
2932

33+
private final static Logger logger = Logger.getLogger(MagicPlugDescriptor.class.getName());
34+
3035
@Override
3136
public boolean isApplicable(AbstractProject<?, ?> item) {
3237
return true;
@@ -43,7 +48,7 @@ public MagicPlugDescriptor() {
4348
}
4449

4550
public FormValidation doPing() throws IOException, ServletException {
46-
System.out.println("doPing");
51+
logger.info("doPing");
4752
if (new CapabilityService().ping()) {
4853
return FormValidation.ok("Ping Successful");
4954
} else {
@@ -72,7 +77,7 @@ public ListBoxModel doFillBrowserNameItems(@QueryParameter String operatingSyste
7277
items.add(Constant.DEFAULT_BROWSER_NAME_VALUE, Constant.EMPTY);
7378
return items;
7479
}
75-
System.out.println(operatingSystem);
80+
logger.info("operatingSystem : +" + operatingSystem);
7681
Set<String> supportedBrowsers = CapabilityService.getBrowserNames(operatingSystem);
7782
if (!CollectionUtils.isEmpty(supportedBrowsers)) {
7883
supportedBrowsers.forEach(br -> {
@@ -85,10 +90,10 @@ public ListBoxModel doFillBrowserNameItems(@QueryParameter String operatingSyste
8590
public ListBoxModel doFillBrowserVersionItems(@QueryParameter String operatingSystem,
8691
@QueryParameter String browserName) {
8792
ListBoxModel items = new ListBoxModel();
88-
System.out.println(operatingSystem + "::" + browserName);
93+
logger.info(operatingSystem + "::" + browserName);
8994
if (!StringUtils.isBlank(operatingSystem) && StringUtils.isBlank(browserName)) {
9095
browserName = "Chrome";
91-
System.out.println("Chrome added");
96+
logger.info("Chrome added");
9297
} else if (StringUtils.isBlank(operatingSystem) || StringUtils.isBlank(browserName)) {
9398
items.add(Constant.DEFAULT_BROWSER_VERSION_VALUE, Constant.EMPTY);
9499
return items;
@@ -108,7 +113,7 @@ public ListBoxModel doFillResolutionItems(@QueryParameter String operatingSystem
108113
items.add(Constant.DEFAULT_RESOLUTION_VALUE, Constant.EMPTY);
109114
return items;
110115
}
111-
System.out.println(operatingSystem);
116+
logger.info("operatingSystem : " + operatingSystem);
112117
List<String> supportedBrowsers = CapabilityService.getResolutions(operatingSystem);
113118
if (!CollectionUtils.isEmpty(supportedBrowsers)) {
114119
supportedBrowsers.forEach(br -> {
@@ -120,9 +125,9 @@ public ListBoxModel doFillResolutionItems(@QueryParameter String operatingSystem
120125

121126
public ListBoxModel doFillCredentialsIdItems(@QueryParameter String credentialsId) {
122127
if (!StringUtils.isBlank(credentialsId)) {
123-
System.out.println(credentialsId);
128+
logger.info(credentialsId);
124129
} else {
125-
System.out.println("Not Found");
130+
logger.info("Not Found");
126131
}
127132
return new ListBoxModel();
128133
}
@@ -131,4 +136,81 @@ public ListBoxModel doFillCredentialsIdItems(ItemGroup context) {
131136
return new StandardListBoxModel().withEmptySelection().withMatching(CredentialsMatchers.always(),
132137
MagicPlugCredentialsImpl.all(context));
133138
}
139+
140+
public ListBoxModel doFillPlatformNameItems() {
141+
Map<String, String> supportedPlatforms = AppAutomationCapabilityService.getPlatformNames();
142+
logger.info("OS triggered : " + supportedPlatforms);
143+
ListBoxModel items = new ListBoxModel();
144+
items.add(Constant.DEFAULT_PLATFORM_NAME_VALUE, Constant.EMPTY);
145+
supportedPlatforms.forEach((key, value) -> {
146+
items.add(value, key);
147+
});
148+
return items;
149+
}
150+
151+
public ListBoxModel doFillBrandNameItems(@QueryParameter String platformName) {
152+
ListBoxModel items = new ListBoxModel();
153+
if (StringUtils.isBlank(platformName)) {
154+
items.add(Constant.DEFAULT_BRAND_NAME_VALUE, Constant.EMPTY);
155+
return items;
156+
}
157+
logger.info("platformName : " + platformName);
158+
Set<String> supportedBrands = AppAutomationCapabilityService.getBrandNames(platformName);
159+
logger.info("Brand Names triggered : " + supportedBrands);
160+
if (!CollectionUtils.isEmpty(supportedBrands)) {
161+
supportedBrands.forEach(br -> {
162+
items.add(br, br);
163+
});
164+
}
165+
return items;
166+
}
167+
168+
public ListBoxModel doFillDeviceNameItems(@QueryParameter String platformName, @QueryParameter String brandName) {
169+
ListBoxModel items = new ListBoxModel();
170+
logger.info(platformName + "::" + brandName);
171+
if (!StringUtils.isBlank(platformName) && StringUtils.isBlank(brandName)) {
172+
brandName = "Asus";
173+
logger.info("Asus added");
174+
} else if (StringUtils.isBlank(platformName) || StringUtils.isBlank(brandName)) {
175+
items.add(Constant.DEFAULT_DEVICE_NAME_VALUE, Constant.EMPTY);
176+
return items;
177+
}
178+
logger.info("platformName : " + platformName + "\n" + "brandName : " + brandName);
179+
Set<String> supportedDevices = AppAutomationCapabilityService.getDeviceNames(platformName, brandName);
180+
logger.info("Device Names triggered : " + supportedDevices);
181+
if (!CollectionUtils.isEmpty(supportedDevices)) {
182+
supportedDevices.forEach(br -> {
183+
items.add(br, br);
184+
});
185+
}
186+
return items;
187+
}
188+
189+
public ListBoxModel doFillDeviceVersionItems(@QueryParameter String platformName,
190+
@QueryParameter String deviceName) {
191+
ListBoxModel items = new ListBoxModel();
192+
logger.info(platformName + "::" + deviceName);
193+
if (!StringUtils.isBlank(platformName) && StringUtils.isBlank(deviceName)) {
194+
deviceName = "Zenfone 6";
195+
logger.info("Zenfone 6 added");
196+
} else if (StringUtils.isBlank(platformName) || StringUtils.isBlank(deviceName)) {
197+
items.add(Constant.DEFAULT_DEVICE_VERSION_VALUE, Constant.EMPTY);
198+
return items;
199+
}
200+
Set<String> supportedDeviceVersions = AppAutomationCapabilityService.getDeviceVersions(platformName, deviceName);
201+
logger.info("Device Versions triggered : " + supportedDeviceVersions);
202+
if (!CollectionUtils.isEmpty(supportedDeviceVersions)) {
203+
supportedDeviceVersions.forEach(ver -> {
204+
items.add(ver, ver);
205+
});
206+
}
207+
return items;
208+
}
209+
210+
public ListBoxModel doFillAppId() {
211+
ListBoxModel items = new ListBoxModel();
212+
items.add(Constant.DEFAULT_APP_ID, Constant.EMPTY);
213+
return items;
214+
}
215+
134216
}

0 commit comments

Comments
 (0)