我们知道在selenium自动化编程中通常的脚本编写是这样的:
driver.click(elementLocator);
driver.waitForPageToLoad(waitPeriod);
这两段的代码实现的功能是点击根据定位规则定位得到的按钮,并进行点击,然后,等到页面加载waitPeriod的时长。
这样的代码如果只有一次还好,但是如果需要频繁的这样的操作--点击、等待,点击、等待,这样的话,就需要对这些代码进行封装和优化。
官方文档上是这样说的:
As with any programming, you will want to use utility functions to handle code that would otherwise be duplicated throughout your tests. One way to prevent this is to wrap frequently used selenium calls with functions or class methods of your own design. For example, many tests will frequently click on a page element and wait for page to load multiple times within a test.
说的是如果在一个测试中频繁的出现这样的操作,那么就需要进行