Getting too many syntax error while running scenarios

After running my test scenarios getting too many times these errors;

ERRO[0364] SyntaxError: invalid character ‘<’ looking for beginning of value
running at parse (native)
discoverat getRequest (file:///scripts/common/httpRequestCheck.js:21:41(66))
purchaseat getFusionAuthEntry (file:///scripts/scenarios/visit.js:192:29(26))
at run (file:///scripts/scenarios/visit.js:61:17(14))
at discovery (file:///scripts/scenarios/discovery.js:25:16(20))
at native executor=ramping-vus scenario=discovery source=stacktrace
ERRO[0364] SyntaxError: invalid character ‘<’ looking for beginning of value
running at parse (native)
discoverat getRequest (file:///scripts/common/httpRequestCheck.js:21:41(66))
purchaseat getFusionAuthEntry (file:///scripts/scenarios/visit.js:192:29(26))
at run (file:///scripts/scenarios/visit.js:61:17(14))
at discovery (file:///scripts/scenarios/discovery.js:25:16(20))
at purchase (file:///scripts/scenarios/purchase.js:14:14(4))
at native executor=ramping-vus scenario=purchase source=stacktrace

This is the result of run;

I have search everywhere but couldn’t find the solution, I accept any help, thanks in advance

Hi @Crius , could you share the part of your code where this error appears?

Hi Gino ofc, @Gino
Actually I don’t know which part of my code causes for this error but
These are my files;


httrequestCheck files;

import http from 'k6/http';
import { check, sleep } from "k6";
import { environment, httpStatus, testLabel } from "./constants.js";

export class httpRequestCheck {
  getRequest(testName, endpoint, culture = '', apiResourceKey = '', descContext = '', expectedResponseStatus = httpStatus.ok, expectedTimeMilliseconds = 0, sleepAfterRequestSeconds = 0) {
    var startTime = new Date().getTime();

    const response = http.get(
      endpoint,
      {
        headers: {
          Accepts: "application/json", 
          "content-type": "application/vnd.api+json",
          [environment.apiKeyName]: environment.apiKeyValue
        }
      });
  
    var endTime = new Date().getTime();
    var responseTime = endTime - startTime;
    var jsonResult = JSON.parse(response.body);

    doTestEvaluation(response, responseTime, culture, apiResourceKey, descContext, expectedResponseStatus, expectedTimeMilliseconds, sleepAfterRequestSeconds);

    return jsonResult;
  };

  postRequest(testName, endpoint, culture = '', apiResourceKey = '', descContext = '', expectedResponseStatus = httpStatus.created, expectedTimeMilliseconds = 0, sleepAfterRequestSeconds = 0, postBody) {
    var startTime = new Date().getTime();

    const response = http.post(
      endpoint,
      JSON.stringify(postBody),
      {
        headers: {
          "Content-Type": "application/json", 
          [environment.apiKeyName]: environment.apiKeyValue
        }

      }
    );

    var endTime = new Date().getTime();
    var responseTime = endTime - startTime;
    var jsonResult = JSON.parse(response.body);

    doTestEvaluation(response, responseTime, culture, apiResourceKey, descContext, expectedResponseStatus, expectedTimeMilliseconds, sleepAfterRequestSeconds);

    return jsonResult;
  };

  patchRequest(testName, endpoint, culture = '', apiResourceKey = '', descContext = '', expectedResponseStatus = httpStatus.created, expectedTimeMilliseconds = 0, sleepAfterRequestSeconds = 0, patchBody) {
    var startTime = new Date().getTime();

    const response = http.patch(
      endpoint,
      JSON.stringify(patchBody),
      {
        headers: {
          "Content-Type": "application/json", 
          [environment.apiKeyName]: environment.apiKeyValue
        }

      }
    );

    var endTime = new Date().getTime();
    var responseTime = endTime - startTime;
    var jsonResult = JSON.parse(response.body);

    doTestEvaluation(response, responseTime, culture, apiResourceKey, descContext, expectedResponseStatus, expectedTimeMilliseconds, sleepAfterRequestSeconds);

    return jsonResult;  
  };
}

function doTestEvaluation(response, responseTime, culture, apiResourceKey, descContext, expectedResponseStatus, expectedTimeMilliseconds, sleepAfterRequestSeconds) {
  var testName = '';

  if (culture != '')
    testName += '[' + culture + ']';

  if (apiResourceKey != '')
    testName += ' ' + apiResourceKey;

  if (descContext != '')
    testName += '/' + descContext;

  var aggregateChecks = {
    httpStatus: response.status,
    responseTime: responseTime
  };

  var checkName = [testName,' ',testLabel.httpStatus,' ',expectedResponseStatus].join('');

  if (expectedTimeMilliseconds > 0) {
    checkName = [testName,' ',testLabel.httpStatus,testLabel.responseTime,' ',expectedTimeMilliseconds,].join('');
    check (aggregateChecks, { [checkName]: (r) => (r.httpStatus === expectedResponseStatus && r.responseTime <= expectedTimeMilliseconds ) } );
  } else {
    check (aggregateChecks.httpStatus, { [checkName]: (r) => r === expectedResponseStatus } );
  }

  if (sleepAfterRequestSeconds > 0)
    sleep(sleepAfterRequestSeconds);

}

discoveryScenarios file;

import { sleep } from "k6";
import { dataHelper } from "../common/dataHelper.js";
import { environment, httpQueryStringDelimiter, httpStatus, odataOpertor, testScenario } from "../common/constants.js";
import { httpRequestCheck } from "../common/httpRequestCheck.js";
import { attributeKey, jsonApiQueryKey, resourceKey } from "../common/hollywood-api/keyStrings.js";
import { eventScheduleFilter } from "../common/hollywood-api/filters/eventScheduleFilter.js";
import { geoVenueSearchFilter } from "../common/hollywood-api/filters/geoVenueSearchFilter.js";
import { searchQueryFilter } from "../common/hollywood-api/filters/searchQueryFilter.js";
import { selectedMovieForEventFilter } from "../common/hollywood-api/filters/selectedMovieForEventFilter.js";
import { selectedEventsForMovieVenueFilter } from "../common/hollywood-api/filters/selectedEventsForMovieVenueFilter.js";
import { selectedEventTicketsFilter } from "../common/hollywood-api/filters/selectedEventTicketsFilter.js";

import { visit } from "./visit.js";

var client = null;
var context = null;
var helper = null;
var result = null;

export function discovery () {
    client = new httpRequestCheck();
    helper = new dataHelper();

    var visitor = new visit(testScenario.visit);
    visitor.run(false, false);
    context = visitor.getContextCopy();

    context.testScenarioName = testScenario.discovery;

    simulateAutoCompleteSearchOnString();
    stepThroughComingSoonMoviesShowMore();
    browseMovieDetails();
    stepThroughVenuesShowMore();
    browseVenueDetails();
    selectMovieThatHasEvents();
    var result = browseMovieVenueEvents();
    selectEventGetTickets(result);
    sleep(environment.sleepBetweenRequestsSlow);

    return context;
};

function simulateAutoCompleteSearchOnString() {
    simulateAutoCompleteItem(2);
    simulateAutoCompleteItem(4);
    simulateAutoCompleteItem(6);
    simulateAutoCompleteItem();
    sleep(environment.sleepBetweenRequestsMedium);
}

function simulateAutoCompleteItem(stringLength = null) {
    var searchQuery = environment.searchTestLocationString;
    var searchInclude = [
        resourceKey.venue,
        resourceKey.geoLocation,
        resourceKey.movie + odataOpertor.resourceSeperator + resourceKey.imageContent,
        resourceKey.movie + odataOpertor.resourceSeperator + resourceKey.textContent
    ];

    if (stringLength != null) {
        searchQuery = searchQuery.substring(0,stringLength);
    }

    var searchFilter = new searchQueryFilter(searchQuery, searchInclude);
    client.getRequest(context.testScenarioName, 
        context.searchEndpoint.value + searchFilter.toQueryString(),
        context.currentCulture,
        resourceKey.search,
        '',
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.searchAutocompleteVelocityMilliseconds * .001);
}

function browseVenueDetails() {
    context.venueFeaturesEndpointList.forEach(r => {
        client.getRequest(context.testScenarioName, 
            r,
            context.currentCulture,
            resourceKey.venue,
            resourceKey.features,
            httpStatus.ok,
            environment.timeThresholdMillisecondsFast,
            environment.sleepBetweenRequestsMedium);
    }
    );
}

function browseMovieDetails() {
    var cnt = 0;

    while (cnt < environment.discoveryMovieBrowseCount) {
        var endpoint = context.movieEndpoint.value + '/' + context.currentMovieIdList[cnt] + httpQueryStringDelimiter.queryStringSeperator + jsonApiQueryKey.filter +
        httpQueryStringDelimiter.keyValuePairSeperator + jsonApiQueryKey.include + httpQueryStringDelimiter.valueAssignmentSeperator +
        [ resourceKey.textContent, resourceKey.genres, resourceKey.imageContent, resourceKey.videoContent ].join(',');
        client.getRequest(context.testScenarioName, 
            endpoint,
            context.currentCulture,
            resourceKey.movie,
            'detail',
            httpStatus.ok,
            environment.timeThresholdMillisecondsFast,
            environment.sleepBetweenRequestsMedium);
        cnt++;
    }
}

function browseMovieVenueEvents() {
    //Grab a quick default
    var movieId = context.ticketingMoviesWithVenues[0].movieId;
    var venueId = context.ticketingMoviesWithVenues[0].venueId;
    var scheduleDate = new Date(new Date().toISOString().substring(0,10)).toISOString();

    //Get a known reserved ticketing event
    context.ticketingMoviesWithVenues.every(i => {
        if (environment.venuesToTest.includes(i.venueId)) {
            movieId = i.movieId;
            venueId = i.venueId;
            return false;
        }
        return true;
    });

    var eventsFilter = new selectedEventsForMovieVenueFilter(movieId,
        venueId,
        scheduleDate,
        [ resourceKey.movie, resourceKey.seatingPreview, resourceKey.unavailableSeats, resourceKey.features ],
        [ attributeKey.startTimeLocal ]
        );

    var result = client.getRequest(context.testScenarioName, 
        context.eventEndpoint.value + eventsFilter.toQueryString(),
        context.currentCulture,
        resourceKey.event,
        'browse',
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast);

    return result;
}

function selectEventGetTickets(result) {
    context.selectedEvent = result.data[0];
    var selectedEventTicketsLink = context.selectedEvent.relationships.tickets.links.related;

    var result = client.getRequest(context.testScenarioName, 
        selectedEventTicketsLink,
        context.currentCulture,
        resourceKey.tickets,
        '',
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast);
}

function stepThroughComingSoonMoviesShowMore() {
    var page = client.getRequest(context.testScenarioName, 
        context.comingSoonNextEndpoint,
        context.currentCulture,
        resourceKey.movie,
        'more',
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast);

    var cnt = 1;
    while (cnt < environment.discoveryComingSoonShowMoreDepth && page.links.next != undefined) {
        page = client.getRequest(context.testScenarioName, 
            page.links.next,
            context.currentCulture,
            resourceKey.movie,
            'more',
            httpStatus.ok,
            environment.timeThresholdMillisecondsFast,
            environment.sleepBetweenRequestsSlow);
            cnt++;
    }
}

function selectMovieThatHasEvents() {
    var movieId = context.ticketingMoviesWithVenues[0].movieId;

    var movieFilter = new selectedMovieForEventFilter(movieId,
        [ resourceKey.textContent, resourceKey.genres, resourceKey.imageContent, resourceKey.imageContent ]);

    var result = client.getRequest(context.testScenarioName, 
        context.movieEndpoint.value + movieFilter.toQueryString(),
        context.currentCulture,
        resourceKey.movie,
        'selected',
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast);

    return result;
}

function stepThroughVenuesShowMore() {
    var minRadius = Number(environment.searchMaxRadius);
    var maxRadius = minRadius + minRadius;

    var venueSearchFilter = new geoVenueSearchFilter(
        environment.searchLatitude,
        environment.searchLongitude,
        minRadius,
        maxRadius,
        [
            resourceKey.venue
        ],
        [
            attributeKey.name,
            attributeKey.displayName,
            attributeKey.urlName,
            attributeKey.address,
            attributeKey.location,
            attributeKey.timeZone,
            attributeKey.telephone,
            attributeKey.isOpen,
            attributeKey.isTicketing,
            resourceKey.features
        ]
    );

    if (environment.discoveryVenueShowMoreDepth > 0) {
        var result = client.getRequest(context.testScenarioName, 
            context.geoVenueSearchEndpoint.value + venueSearchFilter.toQueryString(),
            context.currentCulture,
            resourceKey.geoVenueSearch,
            'more',
            httpStatus.ok,
            environment.timeThresholdMillisecondsFast,
            environment.sleepBetweenRequestsFast);
    
        var cnt = 0;
        while (cnt < environment.discoveryVenueShowMoreDepth && result.data.length > 0) {
            //Step Through Venues, get eventSchedule by page
            var currentVenueIdList = [];
            result.data.forEach(r => { currentVenueIdList.push(r.relationships.venue.data.id); });

            var eventsFilter = new eventScheduleFilter(currentVenueIdList,
                [ resourceKey.venue, resourceKey.movie, resourceKey.movie + odataOpertor.resourceSeperator + resourceKey.imageContent ],
                [ attributeKey.id ],
                [ attributeKey.id, attributeKey.image ],
                [ attributeKey.id, attributeKey.scheduleDates ]);
        
            var page = client.getRequest(context.testScenarioName, 
                context.eventScheduleEndpoint.value + eventsFilter.toQueryString(),
                context.currentCulture,
                resourceKey.eventSchedule,
                'more',
                httpStatus.ok,
                environment.timeThresholdMillisecondsFast,
                environment.sleepBetweenRequestsFast);
        
            while (page.links.next != undefined) {
                page = client.getRequest(context.testScenarioName, 
                    page.links.next,
                    context.currentCulture,
                    resourceKey.eventSchedule,
                    'more',
                    httpStatus.ok,
                    environment.timeThresholdMillisecondsFast,
                    environment.sleepBetweenRequestsFast);
            }

            //Check for more items
            venueSearchFilter.geoSearch.minRadius = maxRadius;
            venueSearchFilter.geoSearch.maxRadius = maxRadius + minRadius;
            result = client.getRequest(context.testScenarioName, 
                context.geoVenueSearchEndpoint.value + venueSearchFilter.toQueryString(),
                context.currentCulture,
                resourceKey.geoVenueSearch,
                'more',
                httpStatus.ok,
                environment.timeThresholdMillisecondsFast,
                environment.sleepBetweenRequestsFast); 
            
            cnt++;
        }    
    }
}

purchaseScenarios files;

import { visit } from "./visit.js";
import { environment, httpStatus, testScenario } from "../common/constants.js";
import { httpRequestCheck } from "../common/httpRequestCheck.js"
import { responseHelper } from "../common/dataHelper.js";
import { attributeKey, resourceKey } from "../common/hollywood-api/keyStrings.js";
import { discovery } from "./discovery.js";
import { getZonesWithSeatsFilter } from "../common/hollywood-api/filters/getZonesWithSeatsFilter.js";
import http from "k6/http";

var context = null;
var client = null;

export function purchase () {
    context = discovery();
    context.testScenarioName = testScenario.purchase;
    client = new httpRequestCheck();

    postOrder();
    var result = getSeatMap();
    getSeatMapZonesAndSeats(result);
//  getUnavailableSeats();
    postOrderEvent();
//  postOrderEventTicketsWithSeats();
    getPaymentOptions();
    patchOrderEmailAddress();
//  postOrderPayment();
 };

function patchOrderEmailAddress() {
  var patchBody = {
    "data": {
      "attributes": {
        "version": context.currentOrderVersion,
        "email": [ context.currentUserId , "@hollywood.com" ].join(''),
      },
      "id": context.currentOrder.data.id,
      "relationships": {
        "user": {
          "data": {
            "type": "user",
            "id": context.currentUserId,
          }
        }
      },
      "type": "order"
    },
    "jsonapi": {
      "version": "1.0"
    }
  };

  var result = client.patchRequest(context.testScenarioName, 
    context.currentOrder.data.links.self,
    context.currentCulture,
    resourceKey.order,
    attributeKey.emailAddress,
    httpStatus.ok,
    environment.timeThresholdMillisecondsFast,
    environment.sleepBetweenRequestsFast,
    patchBody);

  return result;
}

function postOrder() {
    var postBody = {
        "data": {
          "type": "order"
        },
        "jsonapi": {
          "version": "1.0"
        }
      };
 
    var result = client.postRequest(context.testScenarioName, 
        context.orderEndpoint.value,
        context.currentCulture,
        resourceKey.order,
        'create',
        httpStatus.created,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast,
        postBody);

    context.currentOrder = result;
    context.currentOrderVersion = result.data.attributes.version;

    return result;
}

function postOrderEvent()
{
  var postOrderEventEndpoint = context.currentOrder.data.relationships.events.links.related;

  var postBody = {
    "data": {
      "relationships": {
        "source": {
          "data": {
            "type": "event",
            "id": context.selectedEvent.id,
          }
        }
      },
      "type": "orderEvent"
    },
    "jsonapi": {
      "version": "1.0"
    }
  };

  var result = client.postRequest(context.testScenarioName, 
    postOrderEventEndpoint,
    context.currentCulture,
    resourceKey.order,
    resourceKey.event,
    httpStatus.created,
    environment.timeThresholdMillisecondsFast,
    environment.sleepBetweenRequestsMedium, //??? - Setting this to fast causes data issue
    postBody);

  var refreshOrder = client.getRequest(context.testScenarioName,
    result.links.up,
    context.currentCulture,
    resourceKey.order,
    'refresh',
    httpStatus.ok,
    environment.timeThresholdMillisecondsFast,
    environment.sleepBetweenRequestsFast
    );

  context.currentOrder = refreshOrder;
  context.currentOrderVersion = refreshOrder.data.attributes.version;

  return result;
}

function postPaymentOption() {

}

function getPaymentOptions() {
  var orderPaymentOptionsEndpoint = context.currentOrder.data.relationships.paymentOptions.links.related;

  var result = client.getRequest(context.testScenarioName, 
    orderPaymentOptionsEndpoint,
    context.currentCulture,
    resourceKey.order,
    resourceKey.paymentOptions,
    httpStatus.ok,
    environment.timeThresholdMillisecondsFast,
    environment.sleepBetweenRequestsMedium);

  return result;
}

function getSeatMap() {
  var seatMapEndpoint = context.selectedEvent.relationships.seatMap.links.related;

  var result = client.getRequest(context.testScenarioName, 
      seatMapEndpoint,
      context.currentCulture,
      resourceKey.seatMap,
      '',
      httpStatus.ok,
      environment.timeThresholdMillisecondsFast,
      environment.sleepBetweenRequestsFast);
  
  return result;
}

function getSeatMapZonesAndSeats(result) {
  var endpoint = result.data.relationships.zones.links.related;
  var seatsFilter = new getZonesWithSeatsFilter([ resourceKey.seats ]);

  var result = client.getRequest(context.testScenarioName, 
    endpoint + seatsFilter.toQueryString(),
    context.currentCulture,
    resourceKey.seatMap,
    resourceKey.zones,
    httpStatus.ok,
    environment.timeThresholdMillisecondsFast,
    environment.sleepBetweenRequestsMedium);

  return result;
}

visit file;


import { sleep } from "k6";
import { environment, httpStatus, odataOpertor } from "../common/constants.js";
import { dataHelper } from "../common/dataHelper.js";
import { attributeKey, filterNameKey, fusionAuthKey, resourceKey, statusKey } from "../common/hollywood-api/keyStrings.js";
import { httpRequestCheck } from "../common/httpRequestCheck.js"

import { eventScheduleFilter } from "../common/hollywood-api/filters/eventScheduleFilter.js";
import { comingSoonMoviesFilter } from "../common/hollywood-api/filters/comingSoonMoviesFilter.js";
import { geoVenueSearchFilter } from "../common/hollywood-api/filters/geoVenueSearchFilter.js";
import { movieCarouselFeatureListFilter } from "../common/hollywood-api/filters/movieCarouselFeatureListFilter.js";
import { userProfileMoviesFilter } from "../common/hollywood-api/filters/userProfileMoviesFilter.js";
import { userProfileVenuesFilter } from "../common/hollywood-api/filters/userProfileVenuesFilter.js";

let context = {
    testScenarioName: '',
    comingSoonPageSize: 10,
    currentCulture: '',
    currentIp: '',
    currentLatitude: 0,
    currentLongitude: 0,
    currentMovieIdList: [],
    currentVenueId: null,
    currentVenueIdList: [],
    currentOrder: null,
    currentOrderVersion: null,
    currentUserId: null,
    homeEndpoint: { key: resourceKey.home, value: environment.apiEndpoint },
    comingSoonNextEndpoint: null,
    cultureEndpoint: null,
    featureListEndpoint: null,
    eventEndpoint: null,
    eventScheduleEndpoint: null,
    movieEndpoint: null,
    orderEndpoint: null,
    searchEndpoint: null,
    selectedEvent: null,
    ticketingVenues: [],
    ticketingMoviesWithVenues: [],
    userEndpoint: null,
    userProfileEndpoint: null,
    userProfileEndpointMovies: null,
    userProfileEndpointVenues: null,
    geoVenueSearchEndpoint: null,
    venueFeaturesEndpointList: []
};

var client = null;
var helper = null;

export class visit {
    constructor(scenarioName) {
        client = new httpRequestCheck();
        helper = new dataHelper();
        context.testScenarioName = scenarioName;
//        context.currentIp = helper.getRandomConfiguredIpAddress(environment.ipLocationSearchList);
    };

    run(returnTicketingEvent = false, returnReservedEvent = false) {
        var result = null;

        result = getFusionAuthEntry();
        result = getHomeDocument();
        result = getCultureHomeDocument(result);
        getEndpointsFromCultureHomeDocument(result);
        result = getMovieCarouselFeatureList();
        result = getUser();
        getUserProfileEndpoint(result);
        result = getGeoVenueSearch();
        getCurrentVenueIdList(result);
        result = getComingSoonMovies();
        getCurrentMovieIdList(result);
        context.comingSoonNextEndpoint = result.links.next;
        result = getUserProfile();
        getUserProfileEndpointsForMoviesAndVenues(result);
        result = getUserProfileVenues();
        result = getUserProfileMovies();
        result = getEventScheduleForVenuesByPage();
        sleep(environment.sleepBetweenRequestsSlow);

        if (returnTicketingEvent) {
            //Placeholder, will eventually return an event from the last call as a purchasable event.
        }
    };

    getContextCopy() {
        //Quick deep copy by converting to string then into new object
        var contextString = JSON.stringify(context);
        return JSON.parse(contextString);
    }
}

function getComingSoonMovies() {
    var movieFilter = new comingSoonMoviesFilter(
        [ statusKey.openingThisWeek, statusKey.comingSoon ],
        [ resourceKey.imageContent ],
        [ attributeKey.releaseDate, attributeKey.sortName, attributeKey.id]);

    return client.getRequest(context.testScenarioName, 
        context.movieEndpoint.value + movieFilter.toQueryString(),
        context.currentCulture,
        resourceKey.movie,
        '',
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast);
}

function getCultureHomeDocument(result) {
    //Get Culture Entry Document For Random Culture in configuration
    context.cultureEndpoint = helper.getRandomConfiguredCultureEndpoint(result,environment.culturesToTest);
    context.currentCulture = context.cultureEndpoint.key;
    return client.getRequest(context.testScenarioName,
        context.cultureEndpoint.value,
        context.currentCulture,
        resourceKey.home,
        '',
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast);
}

function getCurrentVenueIdList(result) {
    context.ticketingVenues = [];
    context.currentVenueIdList = [];
    context.venueFeaturesEndpointList = [];
    result.data.forEach(r => { context.currentVenueIdList.push(r.relationships.venue.data.id); });
    result.included.forEach(r => { if (r.attributes.isTicketing == true) { context.ticketingVenues.push(r.id); } });
    result.included.forEach(r => {
        if (context.venueFeaturesEndpointList.length < environment.discoveryVenueBrowseCount) {
            context.venueFeaturesEndpointList.push(r.relationships.features.links.related);
        }
    });
}

function getCurrentMovieIdList(result) {
    context.currentMovieIdList = [];
    result.data.forEach(r => context.currentMovieIdList.push(r.id));
}

function getEndpointsFromCultureHomeDocument(result) {
    context.featureListEndpoint = helper.getResourceByKey(result, resourceKey.featureList);
    context.userEndpoint = helper.getResourceByKey(result, resourceKey.user);
    context.geoVenueSearchEndpoint = helper.getResourceByKey(result, resourceKey.geoVenueSearch);
    context.movieEndpoint = helper.getResourceByKey(result, resourceKey.movie);
    context.eventEndpoint = helper.getResourceByKey(result, resourceKey.event);
    context.eventScheduleEndpoint = helper.getResourceByKey(result, resourceKey.eventSchedule);
    context.searchEndpoint = helper.getResourceByKey(result, resourceKey.search);
    context.orderEndpoint = helper.getResourceByKey(result, resourceKey.order);
}

function getEventScheduleForVenuesByPage() {
    var eventsFilter = new eventScheduleFilter(context.currentVenueIdList,
        [ resourceKey.venue, resourceKey.movie, resourceKey.movie + odataOpertor.resourceSeperator + resourceKey.imageContent ],
        [ attributeKey.id ],
        [ attributeKey.id, attributeKey.image ],
        [ attributeKey.id, attributeKey.scheduleDates ]);

    var page = client.getRequest(context.testScenarioName, 
        context.eventScheduleEndpoint.value + eventsFilter.toQueryString(),
        context.currentCulture,
        resourceKey.eventSchedule,
        '',
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast);

    context.ticketingMoviesWithVenues = [];
    page.data.forEach(r => {
        if ( context.ticketingVenues.includes(r.relationships.venue.data.id)) {
            context.ticketingMoviesWithVenues.push( { "movieId": r.relationships.movie.data.id, "venueId": r.relationships.venue.data.id  } );
        }
    });

    while (page.links.next != undefined) {
        page = client.getRequest(context.testScenarioName, 
            page.links.next,
            context.currentCulture,
            resourceKey.eventSchedule,
            '',
            httpStatus.ok,
            environment.timeThresholdMillisecondsFast,
            environment.sleepBetweenRequestsFast);
            page.data.forEach(r => {
                if ( context.ticketingVenues.includes(r.relationships.venue.data.id)) {
                    context.ticketingMoviesWithVenues.push( { "movieId": r.relationships.movie.data.id, "venueId": r.relationships.venue.data.id  } );
                }
            });
    }
}

function getFusionAuthEntry() {
    return client.getRequest(context.testScenarioName, 
        environment.fusionAuthEndpoint + environment.fusionAuthConfigurationId,
        '',
        fusionAuthKey.fusionAuth,
        '',
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast);
}

function getGeoVenueSearch() {
    var venueSearchFilter = new geoVenueSearchFilter(
        environment.searchLatitude,
        environment.searchLongitude,
        environment.searchMinRadius,
        environment.searchMaxRadius,
        [
            resourceKey.venue
        ],
        [
            attributeKey.name,
            attributeKey.displayName,
            attributeKey.urlName,
            attributeKey.address,
            attributeKey.location,
            attributeKey.timeZone,
            attributeKey.telephone,
            attributeKey.isOpen,
            attributeKey.isTicketing,
            resourceKey.features
        ]
    );

    return client.getRequest(context.testScenarioName, 
        context.geoVenueSearchEndpoint.value + venueSearchFilter.toQueryString(),
        context.currentCulture,
        resourceKey.geoVenueSearch,
        '',
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast);
}

function getHomeDocument() {
    return client.getRequest(context.testScenarioName, 
              context.homeEndpoint.value,
              context.currentCulture,
              resourceKey.home,
              '',
              httpStatus.ok,
              environment.timeThresholdMillisecondsFast,
              environment.sleepBetweenRequestsFast);
}

function getMovieCarouselFeatureList() {
    var featureListFilter = new movieCarouselFeatureListFilter(filterNameKey.homeCarousel,
        [
            [ resourceKey.items, odataOpertor.resourceSeperator, resourceKey.imageContent ].join(''), 
            [ resourceKey.items, odataOpertor.resourceSeperator, resourceKey.actions, odataOpertor.resourceSeperator, resourceKey.items ].join('')
        ]);

    return client.getRequest(context.testScenarioName, 
        context.featureListEndpoint.value + featureListFilter.toQueryString(),
        context.currentCulture,
        resourceKey.featureList,
        '',
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast);
}

function getUser() {
    var userUrl = context.userEndpoint.value + '/' + environment.visitorUserId;
 
    var result = client.getRequest(context.testScenarioName, 
        userUrl,
        context.currentCulture,
        resourceKey.user,
        '',
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast);

    context.currentUserId = result.data.id;

    return result;
}

function getUserProfile() {
    return client.getRequest(context.testScenarioName, 
              context.userProfileEndpoint,
              context.currentCulture,
              resourceKey.profile,
              '',
              httpStatus.ok,
              environment.timeThresholdMillisecondsFast,
              environment.sleepBetweenRequestsFast);
}

function getUserProfileMovies() {
    var moviesFilter = new userProfileMoviesFilter(
        [ resourceKey.movie, resourceKey.movie + odataOpertor.resourceSeperator + resourceKey.imageContent ]
    );

    return client.getRequest(context.testScenarioName, 
        context.userProfileEndpointMovies + moviesFilter.toQueryString(),
        context.currentCulture,
        resourceKey.profile,
        resourceKey.movie,
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast);
}

function getUserProfileVenues() {
    var venuesFilter = new userProfileVenuesFilter(
        [ resourceKey.venue ],
        [ attributeKey.id ]
    );

    return client.getRequest(context.testScenarioName, 
        context.userProfileEndpointVenues + venuesFilter.toQueryString(),
        context.currentCulture,
        resourceKey.profile,
        resourceKey.venue,
        httpStatus.ok,
        environment.timeThresholdMillisecondsFast,
        environment.sleepBetweenRequestsFast);
}

function getUserProfileEndpoint(result) {
    context.userProfileEndpoint = result.data.relationships.profile.links.related;
}

function getUserProfileEndpointsForMoviesAndVenues(result) {
    context.userProfileEndpointMovies = result.data.relationships.movies.links.related;
    context.userProfileEndpointVenues = result.data.relationships.venues.links.related;
}

load test file;

import { environment, httpStatus } from "./common/constants.js";
import { discovery } from "./scenarios/discovery.js";
import { purchase } from "./scenarios/purchase.js";

export let options = {
  ext: {
    loadimpact: {
      distribution: {
        // nCaliforniaDistribution: { loadZone: 'amazon:us:palo alto', percent: 25 },
        // oregonDistribution: { loadZone: 'amazon:us:portland', percent: 25 },
        nVirginiaDistribution: { loadZone: 'amazon:us:ashburn', percent: 100 },
        // ohioDistribution: { loadZone: 'amazon:us:columbus', percent: 25 }
      },
    },
  },
  userAgent: environment.userAgent,
  scenarios: {
    discovery: {
      executor: 'ramping-vus',
      exec: 'discovery',
      stages: [
        { duration: environment.rampUpDuration, target: environment.discoveryRampUpVirtualUserTarget },
        { duration: environment.sustainDuration, target: environment.discoverySustainVirtualUserTarget },
        { duration: environment.rampDownDuration, target: 0 }
      ]
    },
    purchase: {
      executor: 'ramping-vus',
      exec: 'purchase',
      stages: [
        { duration: environment.rampUpDuration, target: environment.purchaseRampUpVirtualUserTarget },
        { duration: environment.sustainDuration, target: environment.purchaseSustainVirtualUserTarget },
        { duration: environment.rampDownDuration, target: 0 }
      ]
    },
  },
  thresholds: {
    checks: ['rate>0.95'],
    http_req_blocked: ['p(90) < 15', 'p(95) < 80', 'p(99.9) < 150'],
    http_req_duration: ['p(90) < 250', 'p(95) < 500', 'p(99.9) < 1000'],
    http_req_failed: ['rate<0.005'],
    http_req_receiving: ['p(90) < 15', 'p(95) < 80', 'p(99.9) < 150'],
    http_req_sending: ['p(90) < 15', 'p(95) < 80', 'p(99.9) < 150'],
    http_req_tls_handshaking: ['p(99.9) < 75'],
    http_req_waiting: ['p(90) < 100', 'p(95) < 200', 'p(99.9) < 300'],
  }
};

export { discovery };
export { purchase };

Hi, @Crius , I think it could be this… before using response.body, check if it actually has one, if it doesn’t, you can set a default value for it.

1 Like

@Gino How can I check it, I think there is response.body I can see json api on browser. So root cause seems httpRequestCheck file am I right ? And why invalid character looking for a value error appears ?

It looks like the response body you are getting from the API in the getFusionAuthEntry() function is not returning JSON but something beginning with a < character.

I recommend that you console.log(response.body) before trying to parse it so you can see what is in the body.

It might be that you have encountered some error and the API is returning some HTML rather than JSON.

Hopefully this works for you.