【问题标题】:webdriverio 5.7.5 getting error $(...).setValue is not a functionwebdriverio 5.7.5 出现错误 $(...).setValue is not a function
【发布时间】:2019-03-21 20:27:20
【问题描述】:

我有一个可以正常运行的 webdriverio 框架。但最近我在两者之间包含了一个 REST api 调用,从那时起,api 调用之后的任何 wdio 命令都失败了,并显示“不是函数”的错误消息

api 响应成功。如果没有 api,同样的 wdio 方法也会成功执行。

  • 我尝试比较 webdriverio 之前和之后的浏览器会话,它们都相同
    • 我尝试将 api 调用移至单独的文件。但是在执行 api 调用之后,当调用下一步时面临相同的错误消息
    • 我尝试存储和重用浏览器值,但没有用。
    • 我试图打开一个窗口,运行 api 调用,关闭窗口:但是关闭窗口根本不起作用
    • 我尝试使用 url 和标题切换窗口,但没有任何帮助。

如果在两者之间有 api 调用,$ 功能会丢失 wdio 实例的跟踪,这会发生一些奇怪的事情。我正在努力解决这个问题,并且中间没有 api 调用,无法创建我的测试自动化框架。因此,对此的投入将不胜感激。

下面给出我使用的示例代码供您参考

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);
            });
});

【问题讨论】:

    标签: typescript selenium-webdriver mocha.js webdriver-io supertest


    【解决方案1】:

    尝试使用sync-request,而不是supertest。这将使 Rest 请求同步以在测试环境中使用。

    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);
                });
    

    【讨论】:

      猜你喜欢
      • 2015-11-01
      • 2016-06-24
      • 1970-01-01
      • 2022-08-03
      • 1970-01-01
      • 2022-11-05
      • 2015-05-04
      • 2018-07-23
      • 1970-01-01
      相关资源
      最近更新 更多