12
12
import org .openqa .selenium .TakesScreenshot ;
13
13
14
14
import java .io .File ;
15
+ import java .util .HashMap ;
15
16
import java .util .Map ;
16
17
import java .util .Objects ;
17
18
import java .util .logging .Logger ;
@@ -30,16 +31,15 @@ public SmartUIAppSnapshot() {
30
31
this .gson = new Gson ();
31
32
}
32
33
33
-
34
34
public void start (Map <String , String > options ) throws Exception {
35
35
try {
36
36
this .projectToken = getProjectToken (options );
37
37
log .info ("Project token set as: " + this .projectToken );
38
38
} catch (Exception e ){
39
39
log .severe (Constants .Errors .PROJECT_TOKEN_UNSET );
40
- throw new Exception ("Project token is a mandatory field" );
40
+ throw new Exception ("Project token is a mandatory field" , e );
41
41
}
42
- Map <String , String > envVars = System .getenv ();
42
+ Map <String , String > envVars = new HashMap <>( System .getenv () );
43
43
GitInfo git = GitUtils .getGitInfo (envVars );
44
44
// Authenticate user and create a build
45
45
try {
@@ -49,7 +49,7 @@ public void start(Map<String, String> options) throws Exception{
49
49
options .put ("buildName" , this .buildData .getName ());
50
50
} catch (Exception e ) {
51
51
log .severe ("Couldn't create build: " + e .getMessage ());
52
- throw new IllegalStateException ("Couldn't create build: " + e .getMessage ());
52
+ throw new Exception ("Couldn't create build: " + e .getMessage ());
53
53
}
54
54
}
55
55
public void start () throws Exception {
@@ -69,7 +69,7 @@ public void start() throws Exception{
69
69
log .info ("Build ID set : " + this .buildData .getBuildId () + "for Build name : " + this .buildData .getName ());
70
70
} catch (Exception e ) {
71
71
log .severe ("Couldn't create build: " + e .getMessage ());
72
- throw new IllegalStateException ("Couldn't create build: " + e . getMessage () );
72
+ throw new Exception ("Couldn't create build due to : " , e );
73
73
}
74
74
}
75
75
@@ -90,7 +90,7 @@ private String getProjectToken(Map<String, String> options) {
90
90
91
91
public void smartuiAppSnapshot (AppiumDriver appiumDriver , String screenshotName , Map <String , String > options ) throws Exception {
92
92
try {
93
- if (Objects . isNull ( appiumDriver ) ) {
93
+ if (appiumDriver == null ) {
94
94
log .severe (Constants .Errors .SELENIUM_DRIVER_NULL +" during take snapshot" );
95
95
throw new IllegalArgumentException (Constants .Errors .SELENIUM_DRIVER_NULL );
96
96
}
@@ -107,7 +107,7 @@ public void smartuiAppSnapshot(AppiumDriver appiumDriver, String screenshotName,
107
107
uploadSnapshotRequest .setScreenshotName (screenshotName );
108
108
uploadSnapshotRequest .setProjectToken (projectToken );
109
109
Dimension d = appiumDriver .manage ().window ().getSize ();
110
- int w = d .getWidth (), h = d .getWidth ();
110
+ int w = d .getWidth (), h = d .getHeight ();
111
111
uploadSnapshotRequest .setViewport (w +"x" +h );
112
112
log .info ("Device viewport set to: " + uploadSnapshotRequest .getViewport ());
113
113
String platform = "" , deviceName ="" , browserName ="" ;
@@ -117,10 +117,10 @@ public void smartuiAppSnapshot(AppiumDriver appiumDriver, String screenshotName,
117
117
if (options != null && options .containsKey ("deviceName" )){
118
118
deviceName = options .get ("deviceName" ).trim ();
119
119
}
120
- if (Objects . isNull ( deviceName ) || deviceName .isEmpty ()){
120
+ if (deviceName == null || deviceName .isEmpty ()){
121
121
throw new IllegalArgumentException (Constants .Errors .DEVICE_NAME_NULL );
122
122
}
123
- if (Objects . isNull ( platform ) || platform .isEmpty ()){
123
+ if (platform == null || platform .isEmpty ()){
124
124
if (deviceName .toLowerCase ().startsWith ("i" )){
125
125
browserName = "iOS" ;
126
126
}
0 commit comments