背景:selenium自动化测试框架,工具封装的类和方法都练习完了,或者说达到了熟练的程度,那么就要开始封装自己的方法,省去那些重复的代码,当然有实力的还可以构造自己的方法,或许是嫌弃selenium里的方法不够干净利落。
1、我们知道selenium的原理是通过浏览器模拟用户行为像服务器发送请求,然后得到响应的过程,前面有几篇方法将怎样获取页面元素,继而进一步操作,那么想一下,如果case条目或步骤很多,那么同样的方法是否需要重复写,效率也随之降低,切来看看一个场景:get(url)打开浏览器(网址)--查找页面元素findElement(By.xpath())--或clear()\sendKeys()\click()\--:
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import com.java.selenium.constant.Constants;
/**
*