code: private Cookie logInAndObtainCookie(String testName, WebClient webClient, String protectedUrl, String username, String password, String cookieName,
                                          Expectations expectations) throws Exception {
          Page response = invokeProtectedUrlAndValidateResponse(testName, webClient, protectedUrl, expectations);
          doFormLoginAndValidateResponse(response, username, password, expectations);
  
          Cookie cookie = webClient.getCookieManager().getCookie(cookieName);
          assertNotNull("Cookie [" + cookieName + "] was null but should not have been.", cookie);
          return cookie;
      }
docs: Accesses the protected resource and logs in successfully, ensuring that the expected cookie is included in the result.