我想为我的应用程序编写功能测试,我想模拟我的loginService服务,以加快测试速度.我不想模拟$ http,而是内部调用它的服务,但是我不能把一个间谍放在函数loginService.validate上,它将HTTP查询发送到服务器,但它没有被加载,因为它在驱动程序中,而不是在测试本身.我也看了一下addMockModule但我无法理解如何使用它.有一种简单的方法可以做我想要的吗?我看了看这些,但他们没有帮助:
如何从angular2运行时检测到我在e2e测试模式下运行?我有一个会话刷新间隔,我不想在测试模式下设置,以避免与量角器同步问题.
一个明显的答案是寻找一个URL参数.有没有那么脏的解决方案?
EDIT(赏金前的澄清):量角器连接到角度(1或2),以便在评估任何东西之前等待所有未完成的工作完成.这意味着所有突出的角度promises或任何有效的角度timer都将悬挂量角器测试(最终导致它们失败).最常提出的解决方案是设置,browser.ignoreSynchronization = true但这将迫使我在回调链中嵌套所有e2e测试或使用一堆睡眠.可能两者都有.因此,我似乎陷入了摇滚和困难的地方之间,要么在编写e2e测试时遇到真正的艰难经历,要么在特定的应用程序代码行中设置条件,以便在"测试模式"(eww,丑陋)时不运行.我选择更简单的e2e测试,因为我希望将它们写成数百个,到目前为止我们只讨论一个在测试期间不重要的间隔(会话刷新的间隔为30分钟).
我想知道如何在<a>链接上的点击事件后捕获和读取 URL 。
在 onClick 事件中,我们的 javascripthref对所点击链接的实际内容进行一些字符串操作,然后动态window.location.href = myNewReplacebleURL完成。原始href位置不一定是您在 onClick 之后到达的位置。
这是我开始的方式:
describe("Twitter", function() {
it("Should assert that via value is set correctly in JS", function() {
cy.server();
cy.visit(Cypress.config("appUrl") + "/probes/sha/sha-via.html");
cy.get("#v_test ul.share li a")
.click();
});
});
Run Code Online (Sandbox Code Playgroud)
编辑:我想要的是捕获位于“页面加载”步骤的 URL。
我正在使用一些 bazel 测试目标(scala 风格java_test)运行 E2E 测试。
在 Maven 中,我曾经将日志转储到target/logs在测试期间创建的文件夹,然后如果出现故障 - 我可以查看该文件夹并找到日志。
在 bazel 中 - 我可以在我的测试日志配置中放入什么路径,以便在测试完成/测试失败时可以写并且方便地使用它?
我知道该java.io.tmp目录是可写的,但在测试完成后立即被删除。
我的 jasmine2/protractor 测试看起来像这样
var testUserId = null;
describe("user test", function() {
beforeAll(function(done) {
createTestUser().
.then(function(userId){testUserId = userId})
.then(done)
.catch(done.fail);
it("should do stuff with the test user", function(done) {
// bla bla
});
afterAll(function(done) {
deleteTestUser(testUserId).
.then(done)
.catch(done.fail);
});
})
Run Code Online (Sandbox Code Playgroud)
createTestUser 和 deleteTestUser 返回承诺。如果出现问题,他们会拒绝并显示错误消息。可能现在的问题是,即使在 beforeAll 中发生错误,测试也会开始。我得到
Failures:
1) should do stuff with the test user
Message: [my error message from beforeAll]
Run Code Online (Sandbox Code Playgroud)
如果有很多测试,它会尝试执行所有测试并失败并显示非常相同的错误消息。如果 beforeAll 函数失败,是否可以阻止它执行测试?
谢谢!
(“茉莉花核心”:“2.8.0”,“量角器”:“5.2.1”)
编辑:
这不完全是我所要求的,但至少我找到了一个解决方案来保持错误消息的数量,如下所示:
var testUserId = null;
describe("user test", function() {
beforeAll(function(done) {
createTestUser().
.then(function(userId){testUserId = …Run Code Online (Sandbox Code Playgroud) 我正在寻找使用 Cypress测试像https://github.com/brijeshb42/medium-draft这样的文本编辑器。但是我找不到使用它选择文本的方法。有没有人知道如何做到这一点?
我必须选择一个特定的文本范围才能使测试有效。
/**
Used to get the periodic analytic id.
Whenever we are viewing an asset, the server must respond with an id.
This id is later used by the client, to send periodic analytics.
@param {object} t Testcafe's test controller
@param {object} logger A testcafe's RequestLogger.
@returns {string} Returns the periodic analytic id.
*/
async getPeriodicAnalyticId(t, logger) {
const logPrefix = 'Get periodic analytic id > ';
let responseBody;
await t
.expect(logger.requests.length).gt(0, logPrefix + 'No …Run Code Online (Sandbox Code Playgroud) 我正在测试一个页面,该页面具有一个带有嵌入代码的文本框和一个“复制”按钮,该按钮应该将文本框的内容复制到剪贴板上,以便用户可以将其粘贴到其他地方。有没有办法测试单击“复制”按钮并验证剪贴板内容是否与文本框的内容匹配?谢谢!
我正在尝试使用 jest 和 nestjs 运行 e2e 测试,但遇到了最奇怪的错误,该错误在我的 google 搜索中没有返回任何内容(ExpressAdapter 不是构造函数):
$ env-cmd -f .env.test jest --config ./test/jest-e2e.json
FAIL test/sensor.e2e-spec.ts (29.498 s)
SensorController (e2e)
× /sensors (GET) (15165 ms)
? SensorController (e2e) › /sensors (GET)
Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.
at mapper (../node_modules/jest-jasmine2/build/queueRunner.js:29:45)
? SensorController (e2e) › /sensors (GET)
TypeError: Cannot read property 'getHttpServer' …Run Code Online (Sandbox Code Playgroud) 我的排毒设置在 android 上运行良好,但我在 iOS 上遇到了问题。
问题是应用程序在从 Metro 打包器加载包后卡在启动/启动屏幕上。排毒记录不多:
App has not responded to the network requests below:
(id = -1000) isReady: {}
Unresponded network requests might result in timeout errors in Detox tests.
Run Code Online (Sandbox Code Playgroud)
设置如下所示:
.detoxrc.json
...
"ios.sim.debug": {
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/<app_name>.app",
"build": "xcodebuild -workspace ios/<project_name>.xcworkspace -scheme <scheme> -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
"type": "ios.simulator",
"device": {
"type": "iPhone 11 Pro"
}
},
...
Run Code Online (Sandbox Code Playgroud)
e2e/Login.e2e.js
App has not responded to the network requests below:
(id = -1000) isReady: {}
Unresponded network …Run Code Online (Sandbox Code Playgroud) e2e-testing ×10
protractor ×3
cypress ×2
javascript ×2
testcafe ×2
testing ×2
angular ×1
angularjs ×1
bazel ×1
clipboard ×1
detox ×1
jasmine ×1
java ×1
jestjs ×1
nestjs ×1
node.js ×1
react-native ×1
tdd ×1