0 votes
in Education by (1.7m points)
I am have a working webdriverio framework which executes without any issue. But recently I included a REST api call in between and since then any wdio commands followed the api call is failing with the error message that "is not a function"

The api response is successful. Without api the same wdio methods are executed successfully.

I tried to compare the browser session before and after webdriverio and they both are same

I tried moving the api call to a seperate file. But after the execution of api call, when the next step is called facing the same error message

I tried to store and reuse the browser value, but no good.

I tried to open a window , run the api call , close the window : But close window is not working at all

I tried switch window using the url and title, but did not help at all.

Something happens weird that $ functionality loses the track of wdio instance if there is an api call in between. I am struggling to fix this and without having api call in between , cant create my test automation framework. Hence input on this will be much appreciated.

The sample code I used is given below for your refeence

import { expect } from 'chai';

import apiCheck from 'src/ext/api.check';

import lPage from 'src/pages/login.page';

import sPage from 'src/pages/summary.page';

let superTest = require('supertest');

const request = superTest('http://localhost:3000/api/');

const apiEndPoint = 'auth/login';

const headerOrigin = 'http://localhost:3001';

const headerCookie = '__DEEI_SESSION__=abcd1234';

describe('fund part ', () => {

        beforeEach(() => {



        it('Get API Response in seperate ts file and run through wdio steps', async () => {

            let accountNo = lPage.getLoginAccountType('Standard');

            try {

                    let res = await apiCheck.getApiLoginData(accountNo);


                } catch (error) {



            lPage.enterLoginData(accountNo, '2dsXS£');


        it('Get API Response in same it block and run through wdio steps', async () => {

            let accountNo = lPage.getLoginAccountType('Standard');

            let requestBody = `{"username": \"${accountNo}\", "password": "2dsXS£$"}`;

            let response = await request



                .set('Origin', headerOrigin)

                .set('Content-Type', 'application/json')

                .set('Cookie', headerCookie)


            lPage.enterLoginData(accountNo, password);



JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by (1.7m points)
Instead of supertest, try using sync-request. This would make Rest request synchronous for use in testing environment.

const request = require('sync-request');

it('Get API Response in same it block and run through wdio steps', () => {

            let accountNo = lPage.getLoginAccountType('Standard');

            let requestBody = `{"username": \"${accountNo}\", "password": "2dsXS£$"}`;

            let response = request(




                    headers: { _SOME_HEADER_IF_NEEDED_},

                    json: {_JSON_FOR_POST}



            lPage.enterLoginData(accountNo, password);