2323import io .appium .java_client .LocksDevice ;
2424import io .appium .java_client .android .AndroidDriver ;
2525import io .appium .java_client .ios .IOSDriver ;
26- import org .apache .commons .io .IOUtils ;
2726import org .apache .http .HttpEntity ;
28- import org .apache .http .HttpHost ;
2927import org .apache .http .HttpResponse ;
3028import org .apache .http .client .HttpClient ;
3129import org .apache .http .client .methods .HttpGet ;
3230import org .apache .http .impl .client .HttpClientBuilder ;
33- import org .apache .http .impl .client .LaxRedirectStrategy ;
34- import org .apache .http .message .BasicHttpEntityEnclosingRequest ;
3531import org .apache .http .util .EntityUtils ;
3632import org .apache .logging .log4j .LogManager ;
3733import org .apache .logging .log4j .Logger ;
6561import org .openqa .selenium .logging .LogType ;
6662import org .openqa .selenium .logging .LoggingPreferences ;
6763import org .openqa .selenium .remote .*;
68- import org .openqa .selenium .remote .http .HttpClient .Factory ;
6964import org .openqa .selenium .safari .SafariOptions ;
7065import org .springframework .beans .factory .annotation .Autowired ;
7166import org .springframework .stereotype .Service ;
7267
7368import java .io .IOException ;
74- import java .io .InputStream ;
75- import java .io .StringWriter ;
76- import java .net .InetSocketAddress ;
7769import java .net .MalformedURLException ;
7870import java .net .URL ;
7971import java .time .Duration ;
80- import java .util .ArrayList ;
81- import java .util .HashMap ;
82- import java .util .List ;
83- import java .util .Map ;
72+ import java .util .*;
8473import java .util .concurrent .TimeUnit ;
8574import java .util .logging .Level ;
8675
87- import org .apache .http .impl .client .CloseableHttpClient ;
8876import org .cerberus .core .crud .entity .Application ;
8977import org .cerberus .core .crud .entity .Invariant ;
9078import org .cerberus .core .crud .entity .Parameter ;
@@ -563,6 +551,10 @@ private String guessRobotProvider(String host) {
563551 private MutableCapabilities setCapabilities (TestCaseExecution tCExecution ) throws CerberusException {
564552 // Instanciate DesiredCapabilities
565553 MutableCapabilities caps = new MutableCapabilities ();
554+ Map <String , Object > cloudOptions = new HashMap <>(); //Selenium Capabilities when testing cloud provider is used
555+ Map <String , Object > appiumOptions = new HashMap <>(); //Appium Capabilities
556+ Map <String , Object > cloudAppiumOptions = new HashMap <>(); //Appium Capabilities when testing cloud provider is used
557+
566558 // In case browser is not defined at that level, we force it to firefox.
567559 if (StringUtil .isEmptyOrNull (tCExecution .getBrowser ())) {
568560 tCExecution .setBrowser ("" );
@@ -646,7 +638,7 @@ private MutableCapabilities setCapabilities(TestCaseExecution tCExecution) throw
646638 }
647639 }
648640
649- // if application is a mobile one, then set the "app" capability to theapplication binary path
641+ // if application is a mobile one, then set the "app" capability to the application binary path
650642 if (tCExecution .getApplicationObj ().getType ().equalsIgnoreCase (Application .TYPE_APK )
651643 || tCExecution .getApplicationObj ().getType ().equalsIgnoreCase (Application .TYPE_IPA )) {
652644 // Set the app capability with the application path
@@ -674,64 +666,68 @@ && isNotAlreadyDefined(caps, "appWaitActivity"))) {
674666 switch (tCExecution .getRobotProvider ()) {
675667 case TestCaseExecution .ROBOTPROVIDER_BROWSERSTACK :
676668 if (!StringUtil .isEmptyOrNull (tCExecution .getTag ()) && isNotAlreadyDefined (caps , "build" )) {
677- caps . setCapability ("build" , tCExecution .getTag ());
669+ cloudOptions . put ("build" , tCExecution .getTag ());
678670 }
671+
679672 if (isNotAlreadyDefined (caps , "project" )) {
680- caps .setCapability ("project" , tCExecution .getApplication ());
673+ cloudOptions .put ("project" , tCExecution .getApplication ());
674+ } else {
675+ cloudOptions .put ("project" , caps .getCapability ("project" ));
681676 }
677+
682678 if (isNotAlreadyDefined (caps , "name" )) {
683679 String externalExeName = parameterService .getParameterStringByKey ("cerberus_browserstack_defaultexename" , tCExecution .getSystem (), "Exe : %EXEID%" );
684680 externalExeName = externalExeName .replace ("%EXEID%" , String .valueOf (tCExecution .getId ()));
685681 externalExeName = externalExeName .replace ("%TESTFOLDER%" , String .valueOf (tCExecution .getTest ()));
686682 externalExeName = externalExeName .replace ("%TESTID%" , String .valueOf (tCExecution .getTestCase ()));
687683 externalExeName = externalExeName .replace ("%TESTDESCRIPTION%" , String .valueOf (tCExecution .getDescription ()));
688- caps . setCapability ("name" , externalExeName );
684+ cloudOptions . put ("name" , externalExeName );
689685 }
686+
690687 if (tCExecution .getVerbose () >= 2 ) {
691688 if (isNotAlreadyDefined (caps , "browserstack.debug" )) {
692- caps . setCapability ("browserstack.debug" , true );
689+ cloudOptions . put ("browserstack.debug" , true );
693690 }
694691 if (isNotAlreadyDefined (caps , "browserstack.console" )) {
695- caps . setCapability ("browserstack.console" , "warnings" );
692+ cloudOptions . put ("browserstack.console" , "warnings" );
696693 }
697694 if (isNotAlreadyDefined (caps , "browserstack.networkLogs" )) {
698- caps . setCapability ("browserstack.networkLogs" , true );
695+ cloudOptions . put ("browserstack.networkLogs" , true );
699696 }
700697 }
701698
702699 //Create or override these capabilities if proxy required.
703700 if (StringUtil .parseBoolean (tCExecution .getRobotExecutorObj ().getExecutorProxyType ())) {
704- caps . setCapability ("browserstack.local" , true );
705- caps . setCapability ("browserstack.user" , tCExecution .getRobotExecutorObj ().getHostUser ());
706- caps . setCapability ("browserstack.key" , tCExecution .getRobotExecutorObj ().getHostPassword ());
707- caps . setCapability ("browserstack.localIdentifier" , tCExecution .getExecutionUUID ());
701+ cloudOptions . put ("browserstack.local" , true );
702+ cloudOptions . put ("browserstack.user" , tCExecution .getRobotExecutorObj ().getHostUser ());
703+ cloudOptions . put ("browserstack.key" , tCExecution .getRobotExecutorObj ().getHostPassword ());
704+ cloudOptions . put ("browserstack.localIdentifier" , tCExecution .getExecutionUUID ());
708705 }
709-
710706 break ;
711707 case TestCaseExecution .ROBOTPROVIDER_LAMBDATEST :
712708 if (!StringUtil .isEmptyOrNull (tCExecution .getTag ()) && isNotAlreadyDefined (caps , "build" )) {
713- caps . setCapability ("build" , tCExecution .getTag ());
709+ cloudOptions . put ("build" , tCExecution .getTag ());
714710 }
715711 if (isNotAlreadyDefined (caps , "name" )) {
716712 String externalExeName = parameterService .getParameterStringByKey ("cerberus_lambdatest_defaultexename" , tCExecution .getSystem (), "Exe : %EXEID% - %TESTDESCRIPTION%" );
717713 externalExeName = externalExeName .replace ("%EXEID%" , String .valueOf (tCExecution .getId ()));
718714 externalExeName = externalExeName .replace ("%TESTFOLDER%" , String .valueOf (tCExecution .getTest ()));
719715 externalExeName = externalExeName .replace ("%TESTID%" , String .valueOf (tCExecution .getTestCase ()));
720716 externalExeName = externalExeName .replace ("%TESTDESCRIPTION%" , String .valueOf (tCExecution .getDescription ()));
721- caps . setCapability ("name" , externalExeName );
717+ cloudOptions . put ("name" , externalExeName );
722718 }
723719 if (tCExecution .getVerbose () >= 2 ) {
724720 if (isNotAlreadyDefined (caps , "video" )) {
725- caps . setCapability ("video" , true );
721+ cloudOptions . put ("video" , true );
726722 }
727723 if (isNotAlreadyDefined (caps , "visual" )) {
728- caps . setCapability ("visual" , true );
724+ cloudOptions . put ("visual" , true );
729725 }
730726 if (isNotAlreadyDefined (caps , "network" )) {
731- caps . setCapability ("network" , true );
727+ cloudOptions . put ("network" , true );
732728 }
733729 if (isNotAlreadyDefined (caps , "console" )) {
734- caps . setCapability ("console" , true );
730+ cloudOptions . put ("console" , true );
735731 }
736732 }
737733 break ;
@@ -744,7 +740,7 @@ && isNotAlreadyDefined(caps, "appWaitActivity"))) {
744740 externalExeName = externalExeName .replace ("%TEST%" , String .valueOf (tCExecution .getTest ()));
745741 externalExeName = externalExeName .replace ("%TESTCASE%" , String .valueOf (tCExecution .getTestCase ()));
746742 externalExeName = externalExeName .replace ("%TESTCASEDESC%" , String .valueOf (tCExecution .getTestCaseObj ().getDescription ()));
747- caps . setCapability ("sessionName" , externalExeName );
743+ cloudOptions . put ("sessionName" , externalExeName );
748744 }
749745 if (isNotAlreadyDefined (caps , "sessionDescription" )) {
750746 String externalExeName = parameterService .getParameterStringByKey ("cerberus_kobiton_defaultsessiondescription" , tCExecution .getSystem (), "%TESTCASEDESC%" );
@@ -754,18 +750,18 @@ && isNotAlreadyDefined(caps, "appWaitActivity"))) {
754750 externalExeName = externalExeName .replace ("%TEST%" , String .valueOf (tCExecution .getTest ()));
755751 externalExeName = externalExeName .replace ("%TESTCASE%" , String .valueOf (tCExecution .getTestCase ()));
756752 externalExeName = externalExeName .replace ("%TESTCASEDESC%" , String .valueOf (tCExecution .getTestCaseObj ().getDescription ()));
757- caps . setCapability ("sessionDescription" , externalExeName );
753+ cloudOptions . put ("sessionDescription" , externalExeName );
758754 }
759755
760756 if (isNotAlreadyDefined (caps , "deviceGroup" )) {
761- caps . setCapability ("deviceGroup" , "KOBITON" ); // use UIAutomator2 by default
757+ cloudOptions . put ("deviceGroup" , "KOBITON" );
762758 }
763759 break ;
764760 case TestCaseExecution .ROBOTPROVIDER_NONE :
765761 break ;
766762 default :
767763 }
768-
764+ caps . setCapability ( "cloud:options" , cloudOptions );
769765 return caps ;
770766 }
771767
0 commit comments