我有许多自动化的ui测试,它们使用wdio maxInstances并行运行。在每次测试开始时,我通过执行以下操作来生成一个随机/唯一的手机号码:
07 - All numbers start with this number.
Followed by a 9 digit number based on time & date - `new Date().getTime().toString().substring(4, 13)`不幸的是,我遇到了时间戳有时完全相同的问题。这是因为测试完全在同一时间生成了手机号码。我尝试的第二种方法是:
07 - All numbers start with this number.
Followed by a 6 digit number based on time & date - `new Date().getTime().toString().substring(4, 10)`.
Followed by a 3 digit random number - `Math.floor(Math.random() * 900 + 100);`.这种方法减少了重复生成的手机号码,但我仍然偶尔会生成相同的号码。
我想尝试的另一种方法是获取wdio实例线程/运行器编号,并将其附加到移动编号的末尾。这样,如果在同一时间生成一个编号,线程编号将意味着它将具有唯一的编号。有没有人可以解释一下如何做到这一点。
发布于 2019-10-18 13:20:17
我不确定是否能获得线程数,但我们做了一件不同的事情。我们尝试为每个等级库文件分配唯一的编号。
如下所示:
const fs = require('fs');
//list of features files that we have
let listOfFiles = fs.readdirSync(process.cwd() + '/features');
//Mapping one file with a unique number
let fileMappedWithNumber = listOfFiles.map((file, index) => {
const item = {
file: process.cwd() + '/features/' + file,
number: ++index
}
return item;
});
console.log(JSON.stringify(fileMappedWithNumber));这段代码放在onPrepare钩子中。这个变量fileMappedWithNumber可以是全局赋值的,并且可以在整个代码中使用。
beforeSession钩子中的specs可用于匹配文件。
https://stackoverflow.com/questions/58435701
复制相似问题