测试框架通常不会实现 if 条件,因为它们已经以其原生形式存在。
您可以查看测试框架的源代码以了解它如何进行“如果状态检查”。这将教你如何去做你可能想做的大多数事情(即使在功能测试期间做这些事情并不总是一个好主意)。你也可以看这里:我可以用 KIF 检查屏幕上是否存在视图吗?
此外,您的测试本质上应该是自信的,遵循以下工作流程:
given:
the user has X state setup
(here you write code to assertively setup the state)
It is OK and preferred to isolate your tests and setup
the "given" state (e.g. set login name in the model directly without going
through the UI) as long as you have covered that behavior in another test.
When:
The user tries to do X
(here you tap something etc..)
Then:<br>
The system should respond with Z
(here you verify the system did what you need it)