每次元素出现时,我怎么样才能在每个测试中调用方法?使用Selenium+Java。

huangapple 未分类评论47阅读模式
英文:

How can I call method every time in every test when element appears Selenium+Java?

问题

我想要问的是,是否真的有必要制作一个在每次测试时都会调用的方法,在加载器(动画)出现时等待它消失。起初我考虑制作一个监听器+注解,但我找不到如何做到这一点的信息。我是自动化方面的新手,想向您请教。谢谢!

英文:

I want to ask is it real and useful to make a method which calls every time, in every test when loader (animation) appears and wait that it is disappear. First I think to make a listener + annotation but I can't find info how to do that. I'm new in automation, and ask you. Thank you!

答案1

得分: 0

你可以使用以下方式编写显式等待:

wait.until(ExpectedConditions.invisibilityOf(element))

将此代码放入你的基础/实用/辅助类中,无论你如何构建你的框架。如果加载器在你的测试和应用程序中随处可见,这将非常有用。你可以调用这个通用方法来检查加载器是否在任何地方消失。

或者更进一步,你还可以将元素和超时作为参数传递,并在任何需要检查元素不可见性的情况下使用它,这样会更加通用。

英文:

You may write a an explicit wait using the :
wait.until(ExpectedConditions.invisibilityOf(element))

Put this in a method in your base/utility/helper class however you have structured your framework .It will be useful if the loader appears across your tests and application. And you may call this generic method to check if the loader disappears anywhere.

Or further you can also pass the element & timeout itself as an argument and use it for invisibility of any element, that will be even more generic

huangapple
  • 本文由 发表于 2020年4月10日 20:39:24
  • 转载请务必保留本文链接:https://java.coder-hub.com/61140434.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定