wpf ui github_在github action ci上进行快速ui测试

wpf ui github

This is an ongoing article to chronicle my adventures with continuous integration UI testing for my Swift iOS app. Scroll down for codes and details, read the beginning for the primer and the whys.

这是一篇持续不断的文章,通过对我的Swift iOS应用进行持续集成的UI测试来记录我的冒险经历。 向下滚动以获取代码和详细信息,阅读底漆的开头和原因。

Updated May 2020!

2020年5月更新!

GitHub Actions CI (GitHub Actions CI)

So my app is rather small, but since I’m a solo dev show, I like having a CI to back me up and check my work. And for some strange reason I find CI’s and auto UI testing oddly satisfying (well, when it works…)

所以我的应用程序很小,但是由于我是个开发秀,所以我喜欢用CI来备份并检查我的工作。 出于某种奇怪的原因,我发现CI和自动UI测试令人满足( 很好,当它起作用时…)

Some bits of automated UI testing are great when you get tired of manually re-testing everything, especially as your app grows.

当您厌倦了手动重新测试所有内容时 (尤其是随着应用程序的增长),一些自动化的UI测试非常有用。

BUT if you do any amount of Googling on Swift UI testing, it’s contentious at best and at worst it just fails constantly and/or is horribly flaky. StackOverflow is abound in questions and problems with it.

但是,如果您在Swift UI测试中进行了大量谷歌搜索,那么它充其量是有争议的,而在最坏的情况下,它只会不断失败和/或令人恐惧。 StackOverflow上存在很多问题。

Refer to the man Paul for expert advice on setting it up (rather than trying to figure it out yourself, its painful).

向Paul咨询有关设置的专家建议(而不是自己弄清楚,这很痛苦)。

So, UI testing in hand, now you can invoke a CI to do more than just build.

因此,在进行UI测试之后,现在您可以调用CI来完成不仅仅是构建的任务。

The newly out of beta and IMO badass GitHub Actions capability. Check it out if you haven’t. My app builds are in the order of ~12–14 minutes per, which is not much slower than my MacBook Pro local build time.

最新的beta版本和IMO badass GitHub Actions功能。 如果还没有,请检查一下。 我的应用程序构建时间约为12至14分钟,这并不比MacBook Pro本地构建时间慢多少。

Sidenote: I really like https://www.bitrise.io/ but for my app I’ve found build times are 3x slower than GitHub (aka >30 minutes which exceeds bitrise’s free developer plan) so unfortunately it won’t work for my purposes (it aborts at 30 mins). Bummer!

旁注:我真的很喜欢https://www.bitrise.io/,但是对于我的应用程序,我发现其构建时间比GitHub慢3倍(也就是30分钟,这超过了bitrise的免费开发者计划),因此很遗憾,它不适用于我的目的(在30分钟时终止)。 mm!

适用于iOS的Handy Dandy启动脚本 (Handy Dandy Start Script for iOS)

All right so here’s my GitHub Actions special secret sauce script (not that secret actually). It’s pretty simple, which I prefer because more scripts and macros = more places for shit to break. Simplicity is beautiful. Feel free to amp it up to meet your needs.

好的,这是我的GitHub Actions特殊秘密酱脚本( 实际上不是那个秘密) 。 这很简单,我更喜欢,因为更多的脚本和宏=更多的地方可以打破。 简单就是美丽。 随意放大以满足您的需求。

您可能遇到的问题 (Problems You May Encounter)

相同的确切UI测试根据目的地具有3种不同的行为。 (The same exact UI test has 3 different behaviors based on destination.)

  1. Your local simulators (These seem to always work the best)

    您的本地模拟器(这些模拟器似乎总是工作得最好)
  2. Your local on-device tests

    您的本地设备上测试
  3. Your remote CI server, which is running the command line versions of the xcbuild and xctests (or other things).

    您的远程CI服务器,该服务器正在运行xcbuildxctests (或其他东西)的命令行版本。

The remote CI loves to fail when your local simulator runs just fine. Even running the local command line tools works for my tests, but then fails constantly on the remote. So those are somehow different. GitHub Actions doesn’t tell you much about why, at least not why it’s different than your local.

当本地模拟器运行良好时,远程CI会失败。 甚至运行本地命令行工具都可以进行我的测试,但是随后在远程上经常失败。 所以这些有所不同。 GitHub Actions没有告诉您很多原因,至少没有告诉您为什么它与您的本地用户不同。

Handy Trick: I discovered that the local on-device can sometimes mirror the issues that the remote CI server is having. Swap out #2 and #3 to help get your tests passing and looking green in no time!

Handy Trick:我发现本地设备有时可以反映远程CI服务器遇到的问题。 交换#2和#3可以帮助您的测试通过并立即变成绿色!

超时…超时…为什么总是超时? (Timeouts…timeouts…why is it always timeouts?!)

You’ll notice right away your UI tests will timeout. There are reasons why, beyond the scope of this article, so suffice to say its something we must pay the price of to have such a nice testing capability at all 😆

您会立即注意到您的UI测试将超时。 有充分的理由说明为什么超出本文的讨论范围,我们必须付出一定的代价才能拥有如此出色的测试功能😆

The easier fix is ample use of sleep(1) or sleep(2) gives the UI test framework time to “settle”. But this is not an elegant solution and leads to laggy, longer UI test run times.

更容易的解决方法是充分使用sleep(1) or sleep(2)使UI测试框架有时间“安顿”。 但这不是一个很好的解决方案,并且会导致延迟且较长的UI测试运行时间。

A more elegant solution comes from an article I saw by Sundell here:

我在Sundell的一篇文章中看到了一个更优雅的解决方案:

https://blog.bitrise.io/making-xcode-ui-tests-faster-and-more-stable

https://blog.bitrise.io/making-xcode-ui-tests-faster-and-more-stable

Use before your tap() calls: XCTAssertTrue(cell.waitForExistence(timeout: 10))

在tap()调用之前使用: XCTAssertTrue(cell.waitForExistence(timeout: 10))

Great!

大!

In fact there are 3 other great tips in his article above that are very powerful and I recommend checking out the whole thing above.

实际上,上面他的文章中还有3个很棒的 技巧非常有用,我建议您仔细阅读上面的全部内容。

  1. Use Accessibility identifiers

    使用辅助功能标识符

    ie:

    即:

    tableView.accessibilityIdentifier = "meeting-list"

    tableView.accessibilityIdentifier = "meeting-list"

  2. Capture UI state via the same access IDs

    通过相同的访问ID捕获UI状态

    ie:

    即:

    let titleLabel = cell.staticTexts["meeting-cell-title"]

    let titleLabel = cell.staticTexts["meeting-cell-title"]

  3. Use App Args to set custom testing states

    使用App Args设置自定义测试状态

    ie:

    即:

    app.launchArguments = ["-onboarding-shown", "NO"]

    app.launchArguments = ["-onboarding-shown", "NO"]

在您的视图中弹出键盘 (Keyboard pops up in your view)

Do not forget that the keyboard often pops up on a real device (and not automatically on simulators). What’s extra weird is I found the keyboard behaved like a real device not like a simulator when running on the CI. So this will result in failures to tap buttons or any items covered by the keyboard and you’ll get this lovely error:

不要忘记键盘经常在真实设备上弹出 (而不是在模拟器上自动弹出 )。 更为奇怪的是,我发现键盘在CI上运行时,其行为像真实的设备,而不像模拟器。 因此,这将导致无法点击按钮或键盘所涵盖的任何项目,并且您将得到以下可爱的错误:

Failed: Failed to scroll to visible hide keyboard

Which looks like this in the Actions area. I don’t have the answer to why, but like above I recommend using your local device to run the tests and you’ll sort it out fast enough. Then you can apply the fixes to your UITests and they should pass once more on the CI.

在“动作”区域中看起来像这样。 我没有为什么的答案,但是像上面一样,我建议您使用本地设备来运行测试,这样您就可以足够快地对其进行整理。 然后,您可以将修补程序应用于UITest,它们应该在CI上再次通过。

Image for post
Classic keyboard in my way errors
我的经典键盘出现错误

请记住在测试过程中关闭键盘 (Remember to dismiss the keyboard during the tests)

With the typeText(“\n”) example here:

这里以typeText(“ \ n”)为例:

app.scrollViews.otherElements.tables.buttons["+"].tap()sleep(1) // bad use of sleeps LOLapp.staticTexts["Random"].tap()sleep(2) // don't use these if you dont have to!input = app.textViews[affirm]input.typeText("\n")app.buttons["add_btn"].tap()

You can figure out how having your textviews / textfields setup to handle listening for “\n” ☺️ Stackflow!

您可以弄清楚如何设置textviews / textfields来处理监听“ \ n”” ️Stackflow

这是解决isHittable麻烦的好方法。 (Here is a lovely trick to get around isHittable troubles.)

What your CI usually looks like … 😆

您的CI通常是什么样子...😆

Image for post
x…x…x…x… argh…
x…x…x…x…argh…

What it will look like one day:

一天的样子:

Image for post
Awww jeeea
Awww jeeea

摘要: (Summary:)

The tricks above should help you get a very powerful running example. And if not, feel free to leave a comment with questions and I’m happy to help figure it out!

上面的技巧将帮助您获得一个非常强大的运行示例。 如果没有,请随时提出问题,我很乐意帮助您解决问题!

Happy UX bug hunting!

快乐的UX错误搜寻!

Cheers!

干杯!

翻译自: https://medium.com/swlh/swift-ui-testing-on-github-actions-ci-6267e6620104

wpf ui github

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值