我在JavaScript中创建了一个脚本,在自动浏览器测试期间注入到我们的Ext JS应用程序中.该脚本测量在网格中加载数据所花费的时间.
具体来说,脚本轮询每个网格,查看是否存在第一行或"无数据"消息,并且一旦所有网格满足此条件,脚本将记录Date.now()和performance.timing.fetchStart之间的值. ,并将其视为页面加载的时间.
此脚本或多或少地按预期工作,但与人体测量时间(Google秒表ftw)相比,此测试报告的时间始终比秒表测量的时间长约300毫秒.
我的问题是这些:
脚本如下:
function loadPoll() {
var i, duration,
dataRow = '.firstRow', noDataRow = '.noData',
grids = ['.grid1', '.grid2', '.grid3','.grid4', 'grid5', 'grid6', 'grid7'];
for (i = 0; i < grids.length; ++i) {
var data = grids[i] + ' ' + dataRow,
noData = grids[i] + ' ' + noDataRow;
if (!(document.querySelector(data) || document.querySelector(noData))) {
window.setTimeout(loadPoll, 100);
return;
}
}
duration = Date.now() - performance.timing.fetchStart;
window.loadTime = duration;
}
loadPoll();
Run Code Online (Sandbox Code Playgroud)
一些考虑:
虽然我知道人类的响应时间可能很慢,但我确信使用谷歌秒表的人为因素并未引入300毫秒的不一致性.
查看代码可能看起来多个元素的轮询可能导致300毫秒的不一致,但是当我将被监视的元素数量从7更改为1时,在报告的时间内仍然有300毫秒的剩余时间.自动化测试.
我们的自动化测试在Selenium和Protractor控制的框架中执行.
如果您能够提供任何见解,请提前致谢!
这里有一个简单的问题,我收到了错误: Cannot apply indexing with [] to an expression of type 'System.Array'
public Array hello()
{
var damn = new[] { a2,a3,a4,a5,a6,a7,a8,a9};
return damn;
}
private void a1disable()
{
var a = new[] { a1, a2, a3, a4, a5, a6, a7, a8, a9 };
var b = hello();
a[1].Enabled = false;
b[1].Enabled = false;
}
Run Code Online (Sandbox Code Playgroud)
a[1].Enabled = false;工作绝对没问题!它只是b[1].Enabled = false;抛出我上面描述的错误,我之前没有使用过数组,所以如果答案看起来很明显,我很抱歉,我只是想澄清为什么会发生这种情况.如果你能提供帮助,请提前致谢:)
我正在尝试用数组简化一些长语句,我在这里发现了类似的问题,但我无法解决我出错的地方.代码如下:
if (coursechoice.Text == ("Subsidiary Diploma"))
{
var grade = new[] { grade1, grade2, grade3, grade4, grade5, grade6, grade7, grade8, grade9, grade10, grade11, grade12, grade13, grade14, grade15, grade16, grade17, grade18 };
var unitselect = new[] { unitselect1, unitselect2, unitselect3, unitselect4, unitselect5, unitselect6, unitselect7, unitselect8, unitselect9, unitselect10, unitselect11, unitselect12, unitselect13, unitselect15, unitselect16, unitselect17, unitselect18 };
for (var i = 3; i < 18; i++)
{
grade[i].Enabled = false;
unitselect[i].Enabled = false; // I get index out of bounds of the array …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行四种方法,但每次方法运行之间,我希望程序等待一秒钟.这是代码,我真的不知道如何去做,谢谢你提前!
private void go_Click(object sender, EventArgs e)
{
{
while (GlobalVar.Direction == "down")
{ movedown();}
while (GlobalVar.Direction == "up")
{moveup();}
while (GlobalVar.Direction == "right")
{moveright();}
while (GlobalVar.Direction == "left")
{moveleft();}
}
}
Run Code Online (Sandbox Code Playgroud)