使用 Selenium 驱动程序,IE 在会话之间保持登录状态,而 FF 和 Chrome 则不然。我想根据“已登录”元素 ID 的存在在测试中执行一些附加命令。
如何根据实习生中的条件执行代码?
伪代码:
return command
.get(require.toUrl('http://example.com/'))
.findById('signed-in-user')
.then(function(){
command
.findById('sign-out')
.click()
})
Run Code Online (Sandbox Code Playgroud)
但是当登录用户不存在的情况下如何处理呢?
这是这个问题的重复:How to do Conditional browserInteractions with intern 但与 Intern 2 有关
这有很多组件,我不确定问题出在哪里,但这是我的问题。我正在使用 intern.js 对 SauceLabs 进行 javascript 功能测试。
下面的测试通过了,但是当我转到 SauceLabs 的屏幕截图以查看窗口的行为时,它没有正确滚动到元素,因此.moveMouseTo无法正常工作。
有一点点滚动,但元素仍然不可见。我研究了 Selenium 和 focus,但我是 intern.js 的新手,所以我不确定如何从 Selenium 中的描述中实现这一点,仅在此处发布。
这是测试:
'added comment shows the comment added': function () {
return this.get('remote')
.get(require.toUrl('index.html'))
.setFindTimeout(500)
.setWindowSize(800, 600)
.findByCssSelector('.ht-comment-box')
.click()
.type('My New Comment')
.end()
.findByCssSelector('#addComment')
.click()
.end()
.setFindTimeout(500)
.findByCssSelector('.commentRow:last-child > .commentContent ')
.moveMouseTo()
.getVisibleText()
.then(function (text) {
assert.strictEqual(text, 'My New Comment',
'Adding a comment should display the comment. Showed instead ' + text);
});
},
Run Code Online (Sandbox Code Playgroud)
这是滚动的外观,添加的评论不可见。

Leadfoot作为Intern框架(./node_modules/intern/node_modules/leadfoot)的一部分安装.但是,当我尝试在文档中使用它时(https://theintern.github.io/leadfoot/pollUntil.html):
define([
'intern!object',
'intern/chai!assert',
'require'
], function (registerSuite, assert, require) {
var url = '../../index.html';
var Command = require('leadfoot/Command');
var pollUntil = require('leadfoot/helpers/pollUntil');
registerSuite({
name: 'Todo (functional)',
'submit form': function () {
return this.remote.get(require.toUrl(url))
.findById('new-todo').then(function (val) {}, function(err) {
console.log(err);
}).click();
}
});
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
$ intern-runner config=tests/example_intern
Listening on 0.0.0.0:9000
Starting tunnel...
Error: Attempt to require unloaded module leadfoot/Command
at contextRequire <node_modules/intern/node_modules/dojo/dojo.js:255:12>
at module.require.result <node_modules/intern/node_modules/dojo/dojo.js:284:13>
at </home/bogdanbiv/WebstormProjects/life-tracker3/dojo-example/tests/functional/Todo.js:9:16>
at execModule <node_modules/intern/node_modules/dojo/dojo.js:515:54>
at <node_modules/intern/node_modules/dojo/dojo.js:504:12>
at Array.map <native> …Run Code Online (Sandbox Code Playgroud) 有人能告诉我如何在完成帧切换后继续引用iframe中的元素吗?我已经看过如何切换iframes InternJS中提供的解决方案无效,而实用的功能测试框架中的信息是不适用的(还是.)以下脚本返回错误Cannot read property 'apply' of undefined type: TypeError:
return Remote
.findAllByTagName('iframe')
.then(function (frames) {
return new Remote.constructor(Remote.session)
.switchToFrame(frames[0])
.getProperty('title')
.then(function (result) {
expect(result).to.equal('Rich text editor, rtDescAttach');
});
});
Run Code Online (Sandbox Code Playgroud)
我可以看到脚本失败的唯一原因是框架未正确定位.页面上有两个,我需要第一个.一旦完成,我真的想把一个框架的引用放在一个页面对象(这是我觉得它属于的地方),但我必须能够成功找到它,所以不要把车放在马前.建议和帮助非常感谢.