in Education by
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(() => { browser.url('login?'); }); 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); console.log(res); } catch (error) { console.log(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 .post(apiEndPoint) .send(requestBody) .set('Origin', headerOrigin) .set('Content-Type', 'application/json') .set('Cookie', headerCookie) .expect(200); 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
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( 'POST', '_SOME_POST_END_POINT', { headers: { _SOME_HEADER_IF_NEEDED_}, json: {_JSON_FOR_POST} } ); lPage.enterLoginData(accountNo, password); });

Related questions

0 votes
    I'm trying to enable Slow Query Logging on mysql 5.7 and getting this error: 2016-04-27T14:55:51 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 11, 2022 in Education by JackTerrance
0 votes
    Find the probability of getting 5 exactly twice in 7 throws of a die. Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    I am trying to implement the Hateoas using spring boot. In my UserController class i have used the below ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    Events A and B are such that P(E) = 3 5 , P(F)(B) = 7 12 P (not A or not B) = 1 4 . State whether A and B are independent ? Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    The probability that a person will get an electric contact is 2 5 and the probability that he will not get plumbing ... will get both. Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    We have a repository of logos that we can look up by ID, but there are a few instances where ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I'm playing around with ASP.net MVC and JQuery at the moment. I've come across behavour which ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I'm using $.ajax() to load new pages on my site if certain conditions are met (a flash-based ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    $ (a) Which of the following is used to change the color of hyperlink from blue to any other color? (i) Link ... (iv) none of these 00 Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    The $' present in the RegExp object is called a ____________ (a) character (b) matcher (c) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
0 votes
    What is the use of "$?" sign in shell script?...
asked May 28, 2021 in Technology by JackTerrance
0 votes
    What is the use of "$?" sign in shell script?...
asked Jan 19, 2021 in Technology by JackTerrance
0 votes
    A couple appears in an interview for two vacancies in the same post. The probability of husband getting selected ... will be selected? Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    In a single throw of a die describe the following events: (i) A = Getting a number less than 7 (ii) B = Getting a ... D ∩ F and bar F. Select the correct answer from above options...
asked Nov 22, 2021 in Education by JackTerrance
...