selenium+java+testng分层设计(三)
来源:互联网 发布:网络电视必须买盒子么 编辑:程序博客网 时间:2024/06/01 08:40
这篇主要学会将我们在第二篇中使用到的对元素的操作按照不同的页面放到对应的类中,从第一篇中可知,我们主要涉及到的是一个登录页面,和一个查询页面。则我们可以创建一个action文件夹,包含一个登录页面元素操作,一个查询页面元素操作.。
1.新建一个包com.test.action,在com.test.page中创建两个类,LoginAction、QueryAction.
2.LoginAction的代码如下:
package com.test.action;import org.openqa.selenium.WebDriver;import com.test.page.Loginpage;public class LoginAction { private WebDriver driver; //1)构造方法的方法名必须与类名相同。 //2)构造方法没有返回类型,也不能定义为void,在方法名前面不声明方法类型。 //3)构造方法的主要作用是完成对象的初始化工作,它能够把定义对象时的参数传给对象的域。 public LoginAction(WebDriver driver){ this.driver = driver; } public void Login(String user,String pw) { Loginpage.userName(driver).sendKeys(user); Loginpage.passWord(driver).sendKeys(pw); Loginpage.loginButton(driver).click(); } }3.QueryAction的代码如下:
package com.test.action;import org.openqa.selenium.WebDriver;import com.test.page.Querypage;public class QueryAction { private WebDriver driver; public QueryAction(WebDriver driver){ this.driver = driver; } public void AppQueryButton() throws InterruptedException{ Thread.sleep(2000); Querypage.NextPage(driver).click(); Thread.sleep(2000); Querypage.LastPage(driver).click(); Thread.sleep(2000); Querypage.PageInput(driver).sendKeys("20"); Querypage.Go(driver).click(); Thread.sleep(2000); Querypage.PreviousPage(driver).click(); Thread.sleep(3000); Querypage.FirstPage(driver).click(); Thread.sleep(3000); }}4.test类代码更新为:
package testng;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver;import org.testng.annotations.Test;import org.testng.annotations.BeforeTest;import org.testng.annotations.AfterTest;import com.test.action.LoginAction;import com.test.action.QueryAction;public class test {LoginAction login = null;QueryAction query = null;WebDriver webdriver = new FirefoxDriver();//注意,一定要将该行放在此处,如果放在beforeTest方法中会导致其他方法执行时报空指针异常@BeforeTestpublic void beforeTest() {login = new LoginAction(webdriver);//初始化类webdriver.get("http://123.57.56.45:7778/test/initLogin");webdriver.manage().window().maximize();}@Test(priority=1)public void login()throws InterruptedException {//登录login.Login("999111", "111111");}@Test(priority=2)public void query_keys() throws InterruptedException{ //查询界面按键测试query = new QueryAction(webdriver);//初始化类query.AppQueryButton();} @AfterTest public void afterTest() { webdriver.close(); }}
此时再看test代码是不是要简单多了。
3 0
- selenium+java+testng分层设计(三)
- selenium+java+testng分层设计(一)
- selenium+java+testng分层设计(二)
- selenium+java+testng分层设计(四)
- Selenium+java分层(三)
- Selenium+java分层(一)
- Selenium+java分层(二)
- Selenium+java分层(四)
- Selenium+java分层(五)
- Selenium+java分层(六)
- Selenium+java分层(七)
- 基于TestNG 与Selenium 的自动化测试设计与实施(三)
- selenium第一课(selenium+java+testNG+maven)
- Selenium-java-TestNg-的运行
- [selenium] selenium+java+testNG 显示等待
- [selenium] selenium+java+TestNG 自定义显示等待
- Java+maven+selenium+testng+jenkins自动化环境搭建(补充)
- Web分层设计研究(三)
- Fizz Buzz问题及解法
- [sklearn学习]linear_model.LinearRegression
- [转]手工开栈
- Servlet学习笔记
- a链接
- selenium+java+testng分层设计(三)
- Android组件
- 获取View的宽高
- 下午茶时间 玩会儿数据注入 让DI带我装逼带我灰
- 多个处理器和多核处理器的区别
- AC自动机专题——F
- ios开发之 -- 调用系统定位获取当前经纬度与地理信息
- Nth Digit问题及解法
- js数组方法总结