简体   繁体   中英

Handling concurrent login using cookie based authentication in rest assured java

In my TestNG framework with Rest Assured and java, cookie based authentication is used to login to a web application.

It returns a cookie and authenticity token and have used synchronized on the login method, but when the tests run together on jenkins pipeline, it sometimes fails to make a hit because of concurrent login..

Any other suggestions other than "Synchronized" would be highly appreciated

Let me know if you require any other information

Thanks

Try to perform "login" step before the entire test suite execution, assign returned cookies to a var and pass the value where cookies is passed in. Only after that , start the actual test execution.

Based on your test runner (JUnit or TestNG), pseudo-code is following:

  public class BaseTest {

         @BeforeSuite
         public void fetchCookies() {
              // do login stuff
         }
    
         @BeforeTest
         public void feedCookies() {
              // pass fetched cookies into the rest-assured client
         }  
    
         // run test afterwards
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM