问题标签 [xctestcase]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
575 浏览

ios - XCUIElementQuery.matching(identifier:) 不适用于 UIImageView

我正在尝试实现一个非常简单的测试,但我坚持使用XCUIElementQuery.matching(identifier:)方法。我认为查询UIImageViews 没有按预期工作,但不知道为什么。

我为视图设置了这两个设置:

  1. 标签:使用 id: 'label' 启用可访问性的标签
  2. UIImageView:具有可访问性的 UIImageView 启用了 id: 'accept'

我有这个测试:

我在哪里查询这两个视图(带有 id 的标签和带有 idlabel的 UIImageView accept)。从这里:app简单地定义为像这样的类属性:let app = XCUIApplication()

所以,这就是屏幕的样子: 有 2 个项目的表

这意味着这个测试应该通过,因为屏幕上有两个staticTextidlabel和一个imageid acceptstaticTexts 已成功查询,但matching(identifier:)尝试image使用 id查询时失败accept在 ID 为“接受”的图像上测试失败

我试图查询很多东西,比如:

  • app.images.
  • app.tables.
  • app.tables.images.
  • app.tables.cells.images.
  • app.buttons.(也标记为Button辅助功能设置的特征部分)
  • app.staticTexts.(也标记为Static Text辅助功能设置的特征部分)

但没有运气......我在这里做错了什么,或者遗漏了什么?

0 投票
2 回答
224 浏览

ios - CGFloat Equatable 对于相同的值失败

在此处输入图像描述

运行测试时出现以下错误,如屏幕截图所示:
XCTAssertEqual failed: ("1.4") is not equal to ("1.4") -

有没有人有任何解决方案或解释?

0 投票
1 回答
139 浏览

ios - 在 RxSwift 中使用 Stub 提供程序进行注册验证的 XcTest 案例

我是使用模拟存根的新手,请您帮助任何人!

每次进行注册测试时都会遇到 XCTAssertEqual failed: ("201") is not equal to ("200") 之类的错误。

  • 如何在不使用后端数据的情况下测试硬编码注册详细信息

  • 如何测试状态码对成功和失败的响应

任何帮助都应该不胜感激 - 谢谢

0 投票
1 回答
652 浏览

ios - 如何在 UI 测试中的 tableview 单元格中单独访问两个开关(元素)

我正在 UI 测试我的项目屏幕之一。我有一个表格视图,其中一个单元格包含一个和两个开关。我可以通过以下方式轻松访问第一个单元格的开关(元素)

像这样

但我无法找到任何方法来访问位于侧单元中的下一个剩余的两个开关(元素)。

请告诉我我在这里做错了什么?

此屏幕的调试描述如下(可能有帮助)

"Attributes: Application, 0x1c0380410, pid: 11294, {{0.0, 0.0}, {320.0, 568.0}}, label: \'DummyProject\'\nElement subtree:\n →Application, 0x1c0380410, pid: 11294, {{0.0, 0.0}, {320.0, 568.0}}, label: \'DummyProject\'\n Window, 0x1c03800d0, Main Window, {{0.0, 0.0}, {320.0, 568.0}}\n Other, 0x1c0380270, {{0.0, 0.0}, {320.0, 2.5}}\n Other, 0x1c03804e0, traits: 8589934592, {{0.0, 0.0}, {320.0, 568.0}}\n NavigationBar, 0x1c0380680, traits: 35192962023424, {{0.0, 20.0}, {320.0, 44.0}}, identifier: \'Create a Stream\'\n Button, 0x1c03805b0, traits: 8589934593, {{8.0, 20.0}, {27.0, 44.0}}, label: \'back icon\'\n Other, 0x1c0380820, traits: 8590000128, {{86.5, 30.0}, {147.5, 24.0}}, label: \'Create a Stream\'\n Other, 0x1c0380750, traits: 8589934592, {{0.0, 0.0}, {320.0, 568.0}}\n Other, 0x1c03808f0, traits: 8589934592, {{0.0, 0.0}, {320.0, 568.0}}\n Table, 0x1c0380a90, traits: 35192962023424, {{0.0, 64.0}, {320.0, 504.0}}\n Cell, 0x1c0380b60, traits: 8589934592, {{0.0, 64.0}, {320.0, 153.0}}\n Button, 0x1c0380c30, traits: 8589934593, {{276.0, 75.0}, {33.0, 33.0}}, label: \'camera icon cover images\'\n TextField, 0x1c0380d00, traits: 146029150208, {{10.0, 164.0}, {300.0, 50.0}}, placeholderValue: \'Stream Name\'\n Image, 0x1c0380dd0, traits: 8589934596, {{0.0, 64.0}, {320.0, 153.0}}, identifier: \'add-stream-cover-image-placeholder\'\n Other, 0x1c0380ea0, traits: 8589934592, {{15.0, 216.5}, {305.0, 0.5}}\n Cell, 0x1c419e850, traits: 8589934592, {{0.0, 217.0}, {320.0, 170.0}}\n TextView, 0x1c43804e0, traits: 140746078552064, {{10.0, 261.0}, {300.0, 98.0}}\n StaticText, 0x1c4380680, traits: 8589934656, {{10.0, 242.0}, {300.0, 17.0}}, label: \'Stream Caption\'\n Other, 0x1c43805b0, traits: 8589934592, {{15.0, 386.5}, {305.0, 0.5}}\n Cell, 0x1c4380750, traits: 8589934592, {{0.0, 387.0}, {320.0, 60.0}}\n Switch, 0x1c4380820, traits: 9007207844675585, {{263.0, 401.5}, {49.0, 31.0}}, label: \'Make Private Stream\', value: 0\n StaticText, 0x1c43808f0, traits: 8589934656, {{10.0, 408.5}, {138.0, 17.0}}, label: \'Make Private Stream\'\n Other, 0x1c43809c0, traits: 8589934592, {{15.0, 446.5}, {305.0, 0.5}}\n Cell, 0x1c4380a90, traits: 8589934592, {{0.0, 447.0}, {320.0, 80.0}}\n Switch, 0x1c4380b60, traits: 9007207844675585, {{263.0, 449.0}, {49.0, 31.0}}, label: \'Add Collaborators, Any one can edit\', value: 0\n Switch, 0x1c4380c30, traits: 9007207844675585, {{263.0, 494.0}, {49.0, 31.0}}, label: \'Add Collaborators, Any one can edit\', value: 0\n StaticText, 0x1c4380d00, traits: 8589934656, {{10.0, 456.0}, {138.0, 17.0}}, label: \'Add Collaborators\'\n StaticText, 0x1c4380dd0, traits: 8589934656, {{10.0, 501.0}, {138.0, 17.0}}, label: \'Any one can edit\'\n Other, 0x1c4380ea0, traits: 8589934592, {{10.0, 487.0}, {300.0, 0.0}}\n Other, 0x1c4380f70, traits: 8589934592, {{10.0, 487.0}, {300.0, 0.0}}\n CollectionView, 0x1c4381040, traits: 35192962023424, {{24.0, 487.0}, {273.0, 0.0}}\n Image, 0x1c0380f70, traits: 8589934596, {{291.5, 448.0}, {2.5, 36.0}}\n Image, 0x1c0381040, traits: 8589934596, {{26.5, 481.5}, {265.0, 2.5}}\n Other, 0x1c0381110, traits: 8589934592, {{15.0, 526.5}, {305.0, 0.5}}\n Cell, 0x1c03811e0, traits: 8589934592, {{0.0, 527.0}, {320.0, 80.0}}\n Switch, 0x1c03812b0, traits: 9007207844675585, {{104.5, 561.5}, {49.0, 31.0}}, label: \'Collaborators can, Add Content, Add People\', value: 0\n Switch, 0x1c0381380, traits: 9007207844675585, {{263.0, 561.5}, {49.0, 31.0}}, label: \'Collaborators can, Add Content, Add People\', value: 0\n StaticText, 0x1c0381450, traits: 8589934656, {{10.0, 536.0}, {84.0, 17.0}}, label: \'Collaborators can\'\n StaticText, 0x1c0381520, traits: 8589934656, {{10.0, 568.5}, {88.0, 17.0}}, label: \'Add Content\'\n StaticText, 0x1c03815f0, traits: 8589934656, {{167.0, 568.5}, {88.0, 17.0}}, label: \'Add People\'\n Other, 0x1c03816c0, traits: 8589934592, {{15.0, 606.5}, {305.0, 0.5}}\n Cell, 0x1c0381790, traits: 8589934592, {{0.0, 607.0}, {320.0, 80.0}}\n Other, 0x1c0381860, traits: 8589934592, {{0.0, 64.0}, {305.0, 0.5}}\n Button, 0x1c0381930, traits: 8589934593, {{0.0, 64.0}, {137.0, 45.0}}, label: \'done button\'\n Window, 0x1c0381a00, {{0.0, 0.0}, {320.0, 568.0}}\n Other, 0x1c0381ad0, traits: 8589934592, {{0.0, 0.0}, {320.0, 568.0}}\n Window, 0x1c0381ba0, {{0.0, 0.0}, {320.0, 568.0}}\n StatusBar, 0x1c0381c70, {{0.0, 0.0}, {320.0, 20.0}}\n Other, 0x1c0381d40, {{0.0, 0.0}, {320.0, 20.0}}\n Other, 0x1c0381e10, {{0.0, 0.0}, {320.0, 20.0}}\n Other, 0x1c0381ee0, traits: 8388608, {{6.0, 0.0}, {41.0, 20.0}}, label: \'No SIM\'\n Other, 0x1c0381fb0, traits: 8388608, {{52.0, 0.0}, {15.0, 20.0}}, label: \'3 of 3 Wi-Fi bars\', value: SSID\n Other, 0x1c0382080, traits: 8389120, {{138.0, 0.0}, {49.0, 20.0}}, label: \'7:49 PM\'\n Other, 0x1c0382150, traits: 8388608, {{280.0, 0.0}, {35.0, 20.0}}, label: \'100% battery power, Charging\'\nPath to element:\n →Application, 0x1c0380410, pid: 11294, {{0.0, 0.0}, {320.0, 568.0}}, label: \'DummyProject\'\nQuery chain:\n →Find: Target Application 0x1c02a1c80\n Output: {\n Application, 0x1c0380410, pid: 11294, {{0.0, 0.0}, {320.0, 568.0}}, label: \'DummyProject\'\n }\n"

0 投票
2 回答
3627 浏览

xcode - 获取在 Xcode UI 测试中执行的每个测试用例的结果

在我的 Xcode 测试套件中执行每个测试用例后,我需要测试状态。我知道观察者可以帮助实现它。但是我如何在我的测试中使用它呢?

0 投票
2 回答
3112 浏览

ios - 检查视图控制器是否通过动画成功关闭

我对 iOS 开发人员非常陌生,我正在尝试为一个类编写一个单元测试用例。它只有一个名为 homeButtonTouched() 的方法,可以通过动画关闭视图控制器。我该如何为此编写单元测试?这就是班级的样子。

这是我到目前为止在我的测试课上写的。我只需要填写 testHomeButtonTouched() 方法。

0 投票
1 回答
493 浏览

swift - XCTest UITests 在应用程序启动时失败并出现过期令牌错误

我有几天无法运行 UI 测试。应用程序启动部分出错时失败

过期令牌:此令牌仍然不存在任何操作。

如果我运行包含更多测试的整个类,它们中的大多数会因为同样的原因而失败。

有没有其他人有这个问题?而且,更重要的是,找到了解决此问题的方法?谢谢!

0 投票
1 回答
686 浏览

objective-c - 在测试套件在 XCTest 中完成运行后执行操作

在我的测试套件中的所有测试完成运行后,我需要进行 API 调用。我知道该方法testSuiteDidFinish(_ testSuite: XCTestSuite),该方法确实在测试套件执行后被调用,但是它被调用的次数与我拥有的测试用例的数量一样多。在我的测试套件中,我有三个测试用例。我在测试类中添加了一个观察者。在我的观察者课上,这就是我所拥有的:

“完成”在执行三个测试后打印三次。为什么要这样做?

0 投票
3 回答
3566 浏览

ios - Swift: XCTest Class 'FirstDemoTests' has no initializers

I have the following code (trying to avoid implicit unwrapping):

But I'm getting the following error:

I fixed with this:

Would be a issue using init() in XCTest class?
I'm using Swift 4, Xcode 9.2.

0 投票
2 回答
70 浏览

swift - 如何用 XCTestCases 实现异步任务依赖?

我正在为异步操作编写一些测试用例,其中我有两个需要执行单元测试的操作。

假设我有一些需要调用的登录 web 服务,并且应该调用另一个配置文件 web 服务的响应。

是否可以在 iOS 中使用单元测试来测试上述场景?

先感谢您。