@Maddy Here's a solution I have wherein you can intercept the request API that you are particularly expecting where the code is after user login from the auth step.
Scenario: build percent-encoded auth URL with PKCE S256
#....this will be your code to generate the authURL which you already have above...
# --- Start browser and navigate to auth URL ---
Given driver authUrl
# --- Perform login on Keycloak page ---
And waitFor("input#username")
And input("input#username", username)
And input("input#password", password)
# This is where you can intercept the API so once you click submit it will capture the request.
* def mock = driver.intercept({ patterns: [{ urlPattern: '*/redirect*' }], mock: 'mock.feature' })
And click("input#kc-login, button#kc-login, input[name=login], button[type=submit]")
#---- on a separate feature file you will create mock.feature that will store the #requestPath and requestParams on the intecepted API ---
#Here's my mock.feature file looks like:
@ignore
Feature:
Background:
* def savedRequests = []
Scenario: pathMatches('<substitute this with your API pattern>')
* savedRequests.push({ path: requestPath, params: requestParams })
* print 'saved:', savedRequests
* print savedRequests[0].params.code
* def response = <html><body><h2>Code captured</h2></body></html>