How to use fetchData method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

api.js

Source: api.js Github

copy
1import { fetchData, baseUrl, submitData, isDev } from "./fetch"
2import Vue from "vue"
3
4//公司简介
5export const getCompanyProfile = fetchData('companyProfile')
6
7//项目案例
8export const getCaseList = fetchData('allCaseClassifyDetails')
9
10//联系我们
11export const getContactUs = fetchData('contactUs')
12
13//合作伙伴
14export const cooperativePartner = fetchData('cooperativePartner')
15
16//合作伙伴  GET /portal/
17export const homeData = fetchData('homeData')
18
19export const honor = fetchData('honor')
20
21export const legalStatement = fetchData('legalStatement')
22
23export const menuList = fetchData('menuList')
24export const organizational = fetchData('organizational')
25
26export const productDetails = fetchData('productDetails/{id}')
27
28export const schemeDetails = fetchData('schemeDetails/{id}')
29
30export const technicalSupport = fetchData('technicalSupport')
31
32export const saveOnlineMsg = fetchData('saveOnlineMsg', { method: 'post' })
33
34//招聘
35export const getJoinInfoList = fetchData('jobInfoList')
36export const jobApply = submitData('jobApply')
37
38//新闻 /portal/addBrowseCount/{newsId}
39export const getNewsTypeList = fetchData('getNewsTypeList')
40export const getNewsList = fetchData('getNewsList')
41export const addBrowseCount = fetchData('addBrowseCount/{id}')
42
43//友情链接
44export const getLinksList = fetchData('getLinksList')
45
46//留言类别
47export const getMsgTypeList = fetchData('getMsgTypeList')
48export const getIndexBanner = fetchData('indexBanner')
49
50export const getNewsDetail = fetchData('getNewsDetail/{id}')
51
52let isBGY = window.location.host.indexOf('bgysmartcity') > -1
53
54const getImg = (imgName) => {
55
56    let host = isBGY ? 'http://www.bgysmartcity.com/' : 'http://120.77.220.34',
57        src = imgName
58    if(!/static/.test(imgName)) {
59        src = `${host}//file/${imgName}`
60    }
61    return src
62}
63
64const getCode = (str) => {
65    return `${baseUrl}/portal/captcha.jpg?code=${str}`
66}
67
68Vue.prototype.$api = {
69    technicalSupport, getNewsTypeList,  getNewsList,  addBrowseCount,  getLinksList,
70    schemeDetails, getMsgTypeList, getIndexBanner, getNewsDetail, getCode,
71    productDetails,
72    organizational,
73    menuList,
74    legalStatement,
75    honor,
76    homeData,
77    cooperativePartner,
78    getContactUs,
79    getCaseList,
80    getCompanyProfile,
81    getImg,
82    getJoinInfoList,
83    jobApply,
84    saveOnlineMsg
85}
86
Full Screen

User.js

Source: User.js Github

copy
1const fetch = require('node-fetch');
2const { URLSearchParams } = require('url');
3const Message = require('./Message.js');
4const Reply = require('./Reply.js');
5
6class User{
7    #client;
8
9    constructor(client, data){
10        this.#client = client;
11        if(data.email){
12            this.private = {};
13            this.private.email = data.email;
14            this.private.dob = data.dob;
15        }
16        this.uuid = data.uuid;
17        this.username = data.username;
18        this.displayname = data.displayname;
19		this.followers = data.followers;
20        this.pfp = data.pfp;
21        this.banner = data.banner;
22        this.coins = data.coins;
23        this.rank = data.rank;
24        this.eventr = data.eventr;
25        this.patreon = data.patreon;
26        this.booster = data.booster;
27        this.bio = data.bio;
28        this.nsfw = data.nsfw;
29        this.pronoun = data.pronoun;
30        this.created_at = data.created_at;
31        if(data.posts && data.posts.posts !== null){
32            this.posts = [];
33            data.posts.forEach(post => {
34                post.pfp = this.pfp;
35                this.posts.push(new Message(this.#client, post));
36            });
37        }else{
38            this.posts = null;
39        }
40        if(data.replies && data.replies.replies !== null){
41            this.replies = [];
42            data.replies.forEach(reply => {
43                this.replies.push(new Reply(this.#client, reply));
44            });
45        }else{
46            this.replies = null;
47        }
48    }
49
50    async update(){
51        if(this.private){
52            if(!this.#client.token) throw Error("Bubblez.js error: Not logged in yet");
53            let params = new URLSearchParams();
54            params.append('token', this.#client.token);
55            if(this.#client.verbose == true) console.log(`[Bubblez.js] Sending api request to ${this.#client.apiurl}user/check`);
56            let fetchdata = await fetch(`${this.#client.apiurl}user/check`, {
57                method: 'POST',
58                body: params,
59                headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
60            }).then(r => r.json());
61            if(fetchdata.error != undefined){
62                throw Error(`Bubblez.js error: ${fetchdata.error}`);
63            }
64            this.private = {};
65            this.private.email = fetchdata.email;
66            this.private.dob = fetchdata.dob;
67            this.uuid = fetchdata.uuid;
68            this.username = fetchdata.username;
69            this.displayname = fetchdata.displayname;
70            this.pfp = fetchdata.pfp;
71            this.banner = fetchdata.banner;
72            this.coins = fetchdata.coins;
73            this.rank = fetchdata.rank;
74            this.eventr = fetchdata.eventr;
75            this.patreon = fetchdata.patreon;
76            this.booster = fetchdata.booster;
77            this.bio = fetchdata.bio;
78            this.nsfw = fetchdata.nsfw;
79            this.pronoun = fetchdata.pronoun;
80            this.ban = null;
81            this.created_at = fetchdata.created_at;
82            this.last_posted = null;
83            if(fetchdata.posts && fetchdata.posts.posts !== null){
84                this.posts = [];
85                fetchdata.posts.forEach(post => {
86                    this.posts.push(new Message(this.#client, post));
87                });
88            }else{
89                this.posts = null;
90            }
91            if(fetchdata.replies && fetchdata.replies.replies !== null){
92                this.replies = [];
93                fetchdata.replies.forEach(reply => {
94                    this.replies.push(new Reply(this.#client, reply));
95                });
96            }else{
97                this.replies = null;
98            }
99            return this;
100        }else{
101            if(!this.#client.token) throw Error("Bubblez.js error: Not logged in yet");
102            let params = new URLSearchParams();
103            params.append('username', this.#client.user.username);
104            params.append('token', this.#client.token);
105            if(this.#client.verbose == true) console.log(`[Bubblez.js] Sending api request to ${this.#client.apiurl}user/get`);
106            let fetchdata = await fetch(`${this.#client.apiurl}user/get`, {
107                method: 'POST',
108                body: params,
109                headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
110            }).then(r => r.json());
111            if(fetchdata.error != undefined){
112                throw Error(`Bubblez.js error: ${fetchdata.error}`);
113            }
114            this.uuid = fetchdata.uuid;
115            this.username = fetchdata.username;
116            this.displayname = fetchdata.displayname;
117			this.followers = fetchdata.followers;
118            this.pfp = fetchdata.pfp;
119            this.banner = fetchdata.banner;
120            this.coins = fetchdata.coins;
121            this.rank = fetchdata.rank;
122            this.eventr = fetchdata.eventr;
123            this.patreon = fetchdata.patreon;
124            this.booster = fetchdata.booster;
125            this.bio = fetchdata.bio;
126            this.nsfw = fetchdata.nsfw;
127            this.pronoun = fetchdata.pronoun;
128            this.ban = fetchdata.ban;
129            this.created_at = fetchdata.created_at;
130            this.last_posted = fetchdata.last_posted;
131            if(fetchdata.posts && fetchdata.posts.posts !== null){
132                this.posts = [];
133                fetchdata.posts.forEach(post => {
134                    this.posts.push(new Message(this.#client, post));
135                });
136            }else{
137                this.posts = null;
138            }
139            return this;
140        }
141    }
142}
143
144module.exports = User;
Full Screen

index.js

Source: index.js Github

copy
1import React from "react";
2import ListItem from "../ListItem";
3import "./navbar.css";
4
5const Navbar = ({ dispatch, fetchdata }) => {
6  return (
7    <ul id="navBar">
8      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={1} />
9      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={2} />
10      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={3} />
11      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={4} />
12      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={5} />
13      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={6} />
14      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={6} />
15      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={7} />
16      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={8} />
17      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={9} />
18      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={10} />
19      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={11} />
20      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={12} />
21      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={13} />
22      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={14} />
23      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={15} />
24      <ListItem dispatch={dispatch} fetchdata={fetchdata} weekNumber={16} />
25    </ul>
26  );
27};
28
29export default Navbar;
30
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)