Java脚本-发送在'it'到其他'it'
protractor java script - send var which created in 'it' to other 'it'
我在第一个'it'函数中创建了以下2个变量:' theccurrentaccount;', 'switchToAccount;'
var theCurrentAccount;
var switchToAccount;
it("should find the current account", function () {
ptor.findElements(protractor.By.xpath("...")).then(function (elements) {
if (elements.length > 0){
theCurrentAccount = context.switchAccount.accountName1;
switchToAccount = context.switchAccount.accountName2;
}
else{
theCurrentAccount = context.switchAccount.accountName2;
switchToAccount = context.switchAccount.accountName1;
}
});
});
switchAccount(ptor, switchToAccount);
现在当我调用函数switchAccount时,它是这样定义的:
var switchAccount = function (ptor, id) {
it("should switch account to" + "'#" + id + "'", function () {
});
}
id未定义。我怎样才能做得正确?
首先通读并执行代码的同步部分,然后解析延迟语句。诸如findElements
之类的交互将总是被延迟,但是您也可以将自己的命令插入controlFlow队列中。
var theCurrentAccount;
var theOtherAccount;
var switchAccount = function() {
if (theCurrentAccount === 'name1') {
theCurrentAccount = 'name2';
theOtherAccount = 'name1';
} else if (theCurrentAccount === 'name2') {
theCurrentAccount = 'name1';
theOtherAccount = 'name2';
}
};
it("should find the current account", function () {
expect(theCurrentAccount).toBe(undefined);
expect(theOtherAccount).toBe(undefined);
switchAccount();
expect(theCurrentAccount).toBe(undefined);
expect(theOtherAccount).toBe(undefined);
ptor.findElements(protractor.By.xpath("...")).then(function() {
theCurrentAccount = 'name1';
expect(theCurrentAccount).toBe('name1');
expect(theOtherAccount).toBe(undefined);
switchAccount();
expect(theCurrentAccount).toBe('name2');
expect(theOtherAccount).toBe('name1');
});
expect(theCurrentAccount).toBe(undefined);
expect(theOtherAccount).toBe(undefined);
switchAccount();
expect(theCurrentAccount).toBe(undefined);
expect(theOtherAccount).toBe(undefined);
browser.controlFlow().execute(function() {
expect(theCurrentAccount).toBe('name2');
expect(theOtherAccount).toBe('name1');
switchAccount();
expect(theCurrentAccount).toBe('name1');
expect(theOtherAccount).toBe('name2');
});
expect(theCurrentAccount).toBe(undefined);
expect(theOtherAccount).toBe(undefined);
switchAccount();
expect(theCurrentAccount).toBe(undefined);
expect(theOtherAccount).toBe(undefined);
});
定义这些browser.params
,它们是整个执行过程中的静态变量:
broswer.params.theCurrentAccount = context.switchAccount.accountName1;
broswer.params.switchToAccount = context.switchAccount.accountName2;
这些参数是静态的,可以跨所有规格访问
相关文章:
- 如何添加浮动和非浮动,其他
- 与其他库的jQuery.noConflict()
- 播放当前视频时如何停止其他视频?JavaScript
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- 制作一个不带HTML a标记但在动画播放完毕后指向其他页面的超链接
- 除修剪外的其他功能
- 是什么让一个“;Uncaught RangeError:超过了最大调用堆栈大小“;错误(Chrome,在其他浏览器中显示
- Array.length似乎不起作用;console.log则显示其他情况
- 如何消除代码中的未定义和其他问题
- 如何覆盖锚点元素's href目标,并在我点击转到目标javascript时删除其他错误
- jquery代码在Mozilla中有效,但在其他浏览器上无效
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- Jquery未定义函数正在停止其他操作
- 如何将我的javascript库公开给其他客户端使用
- Javascript阻止其他Javascript代码
- chart.series[id].remove()无法刷新高位图表/高位股票中其他系列的图例属性
- 如何“;过滤器”;或者以其他方式重构该数据
- java脚本在Chrome和其他浏览器中对LocaleTimeString的不同行为
- 为什么下面的if语句排除了一个'It’s和其他的一样
- Java脚本-发送在'it'到其他'it'