webdriverio 5.7.5 获取错误 $(...).setValue 不是函数
webdriverio 5.7.5 getting error $(...).setValue is not a function
我有一个可以正常运行的 webdriverio 框架,可以毫无问题地执行。但最近我在两者之间加入了一个 REST api 调用,此后任何 wdio 命令在 api 调用之后都会失败,并显示错误消息 "is not a function"
api响应成功。没有 api 相同的 wdio 方法执行成功。
- 我试着比较浏览器 session 在 webdriverio 之前和之后,它们都是一样的
- 我尝试将 api 调用移动到一个单独的文件中。但是在执行完api调用之后,在调用下一步的时候面临同样的错误信息
- 我尝试存储和重用浏览器值,但没有用。
- 我尝试打开 window,运行 api 调用,关闭 window :但是关闭 window 根本不起作用
- 我尝试使用 url 和标题切换 window,但没有任何帮助。
如果中间有 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);
});
});
尝试使用 sync-request 而不是超级测试。这将使 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);
});
我有一个可以正常运行的 webdriverio 框架,可以毫无问题地执行。但最近我在两者之间加入了一个 REST api 调用,此后任何 wdio 命令在 api 调用之后都会失败,并显示错误消息 "is not a function"
api响应成功。没有 api 相同的 wdio 方法执行成功。
- 我试着比较浏览器 session 在 webdriverio 之前和之后,它们都是一样的
- 我尝试将 api 调用移动到一个单独的文件中。但是在执行完api调用之后,在调用下一步的时候面临同样的错误信息
- 我尝试存储和重用浏览器值,但没有用。
- 我尝试打开 window,运行 api 调用,关闭 window :但是关闭 window 根本不起作用
- 我尝试使用 url 和标题切换 window,但没有任何帮助。
如果中间有 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);
});
});
尝试使用 sync-request 而不是超级测试。这将使 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);
});