Forum Discussion

HaroldR's avatar
HaroldR
Contributor
8 years ago

Create Add Auth Manager Profiles, set credentials, populate inherit method from Groovy Script

Hello the community,

I am trying to make a groovy script at project level in setup script tab to manage credentials. I would like writing a script to add differents profile and setting eachone to differents testsuite and all test cases nested in the testsuite, as the "Inherit From Parent" Method" does.

Let's take an example with a project containing 2 differents testsuites called respectively MyTestSuite1, and MyTestSuite2. Imagine that MyTestSuite1 and MyTestSuite2, each testsuite contain two differents testcases called MyTestCase1 and MyTestCase2.
I would like populating the AuthProfile created at the project level inside testcases (i.e, MyTestSuite1, MyTestCase1 and MyTestCase2 should use the same authentication, for instance "Profile1"; Idem, MyTestSuite2, MyTestCase1 and MyTestCase2 should use the other authentication profile, "Profile2".

I don't know which classes should I use inside my groovy script to achieve this purpose.

Any suggestions!? Thanks for your interest answering this question

Harold 

    • HaroldR's avatar
      HaroldR
      Contributor

      Hey Nastya_Khovrina 
      Thanks for providing some documentation related to authentication. Finally, I solve my problem thanks to this script :

       

      import com.eviware.soapui.config.AuthEntryTypeConfig;
      
      def project = testRunner.getTestCase().getTestSuite().getProject();
      def authProfile = project.getAuthRepository().createEntry(AuthEntryTypeConfig.BASIC, "User1212165");
      authProfile.setUsername("Username");
      authProfile.setPassword("Password");
      //authProfile.setDomain("NewDomain");
      authProfile.setPreemptive(false);
      
      //def request= testRunner.testCase.getTestStepByName("Name of the Step").getHttpRequest();
      //request.setSelectedAuthProfile("Name of your profile");

      It permit me to add several profiles in Auth Manager window.

      Regards

      HR

      • dhruth's avatar
        dhruth
        Visitor

        Hi, I tried this for SoapUI 5.4 opensource, but not working? Any idea how to achieve the same for open source.

         

        def step = testRunner.testCase.getTestStepByName("Name of the Step").getHttpRequest();
        step.setSelectedAuthProfile("Name of your OAuth profile");

         

        Getting error stating "setSelectedAuthProfile" no method found, 

    • HaroldR's avatar
      HaroldR
      Contributor

      Nastya_Khovrina,

      Any idea of how could I set the authentication profile just created before at : 

      1 - Project level

      2 - TestSuite level

      And at the same time apply the selected authentication profile to all of its childrens
      See image for further informations

      Regards

      Harold

      • Nastya_Khovrina's avatar
        Nastya_Khovrina
        SmartBear Alumni (Retired)

        Hi Harold,

         

        To set the authorization profile for a project and for a testSuite, you can use the setAuthProfile method:

         

         

        import com.eviware.soapui.config.AuthEntryTypeConfig;
        def project = context.getTestCase().getTestSuite().getProject();
        project.setAuthProfile("Name of your Profile");
        def ts = project.getTestSuiteByName("TestSuite Name");
        ts.setAuthProfile("Name of your Profile");

        To set the "Inherit from parent" value for a child, you can use this script:

        def testCase = project.getTestSuiteByName("TestSuite Name").getTestCaseByName("TestCase Name);
        testCase.setAuthProfile("Inherit from parent");

        But, child elements should have this value by default.

         

        Documentation:

        Class WsdlProjectPro: https://www.soapui.org/apidocs/pro/com/eviware/soapui/impl/wsdl/WsdlProjectPro.html