javascript - 如何在执行 Test cafe 脚本时操作 URL
问题描述
我尝试使用命令提示符执行我的 TestCafe 脚本。在执行时,test cafe 通过获取本地 IP、端口号和会话 ID 以及 URL 来开始执行。我希望我的脚本直接在 URL 上执行,而不需要本地主机 IP、端口和其他详细信息。当我在 Test Cafe 上执行我的脚本时,请参考随附的屏幕截图。 带有本地主机 IP、端口的测试咖啡馆脚本的屏幕截图
附件是在Test Cafe上执行的测试用例代码。
import { Selector } from 'testcafe';
import { Crypto } from 'testcafe';
var faker = require('faker');
function randomString(size) {
return crt
.randomBytes(size)
.toString('hex')
.slice(0, size)
};
function numberGen(len) { //Function to Generate random number;
length of number = value specified in 'len'
// var genNum= Math.floor(Math.pow(10, len)*Math.random()).toString()
var text = "";
var charset = "0123456789";
for( var i=0; i < len; i++ ) {
text += charset.charAt(Math.floor(Math.random() * charset.length));}
return text;
};
const dataSet = require('./dataIUT.json');
const crt = require('crypto')
var randomBankAccName = faker.random.alphaNumeric(6)+"Bank";
var AccountNumber = numberGen(9)
var AccountName = "AccName_"+faker.random.alphaNumeric(4)
fixture `CreateBankAccount`
.page `https://dev-assure-claims.dxc-rmcl.com/riskmasterux/#/login?
clientId=3f28130450c00018`
.beforeEach(t => t.resizeWindow(1200, 1100));
dataSet.forEach(data => {
test('CreateBankAccount', async t => {
//==================Login Code With JSON Starts================================
await t
.maximizeWindow()
.typeText(Selector('#username'), data.Username)
.pressKey('tab')
.typeText(Selector('#login-password'), data.Password)
.pressKey('enter')
.click(Selector('[ng-model="dsnSelected"]'))
.click(Selector('[role="option"]').find('span').withText(data.DSN))
.click(Selector('[ng-model="zoneSelected"]'))
.click(Selector('[role="option"]').find('a').withText('Claims'))
.click(Selector('#loginbox').find('button').withText('Continue'))
.wait(1000)
//==================Login Code With JSON Ends================================
//==================Code to Create Bank Account Starts ================================
.click(Selector('#menuBar').find('a').withText('Funds').nth(0))
.click(Selector('#menu_FundsRoot').find('a').withText('Bank Account'))
.switchToIframe(Selector('[id^="bankaccount"]'))
.wait(1000)
//var BankAccount = "BA_"+randomString(4).toUpperCase()
//await t
.click(Selector('#lookup_banklastname'))
.typeText(Selector('#lookup_banklastname'), randomBankAccName).setTestSpeed(0.6).pressKey('tab')
//.click(Selector('#accountnumber'))
.typeText(Selector('#accountnumber'), AccountNumber).setTestSpeed(0.6)
.pressKey('tab')
.click(Selector('#accountname')).typeText(Selector('#accountname'), AccountName).setTestSpeed(0.6)
.pressKey("tab")
.click(Selector('#Save').find('i').withText('save'))
//==================Code to Create Bank Account Endss==================================
//========================Click to RHS Child's Add button Starts=========================
const ele1 = Selector('[class="row main_menu right-panel-bg-hover"]').find('i').withText('add').with({ visibilityCheck: true }) // RHS Menu is available
await t.expect(ele1.exists).ok('', { timeout: 20000 })
.click(ele1)
//========================Click to RHS Child's Add button Ends=========================
//==========================Logout Code Starts==========================================
.switchToMainWindow()
.click(Selector('#morebtn').find('i').withText('more_vert'))
.click(Selector('#menu_othersMenu').find('a').withText('exit_to_appLogout'))
.click(Selector('#btnRoll').find('i').withText('done'));
//===========================Logout Code Ends========================================
});});
解决方案
在 localhost 上“运行”测试会导致什么问题?你到底想解决什么问题?
您看到的是 TestCafe 与本地 TestCafe 服务器进行通信。查看文档,无法让 TestCafe 与不是您当前机器的设备进行通信,所以我认为您想要实现的目标是不可能的。
推荐阅读
- android - 我想在软键盘上方创建一个视图
- amazon-web-services - 如何配置我的 EC2 实例运行 DPDK 以过滤弹性 IP 和另一个 ec2 实例之间的流量?
- python - Extracting name and number from a string
- ruby - 在 Firestore 中写入需要太多时间
- java - 如何使用 log4j 动态设置日志文件名,但在发出数据库请求之后?
- java - 为什么通知没有显示在 API 28 中?
- c - 如何将 VL53L0X 标头包含到我的 STM32L 项目中
- python - pythonscript将图片保存到文件时如何在网络服务器上显示图片?
- visual-studio-code - VSCode Jest 因 SystaxError 失败:意外的令牌 =
- python - 将(冻结的)Tensorflow 模型加载到内存中时出错