Getting error 'The server response could not be parsed as HTML.' when the main request is returning json or other format than html

I’m creating load test suite and on clicking a submit button using ‘loadPageByClick’ I’m getting ‘The server response could not be parsed as HTML.’ and execution is getting stopped as the main request is a post call and returning a json body instead of html. Its the second request which will return the actual html. Please share the workaround for this issue.

Just as summary for everyone based on a side channel conversation with Tony.

This is a pattern seen with the Storefront Reference Architecture (SFRA) by Salesforce Commerce Cloud. SFRA implements a rather unusual redirect schema by returning JSON and using an JavaScript rewrite of an URL returned in that JSON to redirect to a landing page. That makes error handling easier in case the login fails and no page load is desired, but harder to load test it.

We have implemented that pattern as part of Xceptance’s SFRA load test suite, but we cannot share the suite outside of an actual project. Only the base suite of the suite is open sourced, not the SFRA implementation itself (so in case you want to use the page component pattern or some of the other utilities -

Long story short: You have to fire the first request as a plain HttpRequest and take the target URL from the returned JSON. After that, you can just load the page normally with that very URL.

protected void doExecute() throws Exception
    // fill login form, this is a page object pattern and we here just set the parameters at the form
    final HtmlForm form = LoginPage.instance.loginAndCreateAccountCard.fillLoginForm(account);

    // submit form data aka emulate the button click, we post the form as serialized data
    final WebResponse response = new HttpRequest().XHR()

    // map the response data to java class or you can also just take the new target url
    // from the JSON manually
    final Gson gson = Context.getGson();
    final LoginJSON data = gson.fromJson(response.getContentAsString(), LoginJSON.class);
    Assert.assertTrue("Failed submitting login request", data.success);
    // load account detail page, this is now the page load that fetches the regular html
1 Like

Thank you for clarifying the issue. :+1: