java分装

编程入门 行业动态 更新时间:2024-10-15 12:29:37

<a href=https://www.elefans.com/category/jswz/34/1770091.html style=java分装"/>

java分装

代码结构

可以到github上查看

com.zlshuo.selenium.nonaming.driver:生成各浏览器相应的driver

com.zlshuo.selenium.nonaming.driverinstance:获取driverinstance实例

com.zlshuo.selenium.nonaming.element:根据定位器获取元素

com.zlshuo.selenium.nonaming.operation:浏览器、元素等操作方法及断言

com.zlshuo.selenium.nonaming.test:测试用

com.zlshuo.selenium.nonaming.tools:一些工具类

类图

画的比较戳,将就看吧

所需jar包

相关配置

由于用reportng代替了原来testng的测试报告,故需要在eclipse中做如下配置:

1.Window->preferences->TestNG

2.新建testng.xml,写入如下内容

suite SYSTEM ".0.dtd" >

示例代码

package com.zlshuo.selenium.nonaming.test;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;

import com.zlshuo.selenium.nonaming.driverinstance.CreateDriverInstance;

import com.zlshuo.selenium.nonaming.driverinstance.DriverInstance;

public class Try {

private DriverInstance driver=null;

@BeforeMethod

public void setUp(){

//生成chrome的driverInstance

driver=CreateDriverInstance.getDriverInstance("chrome");

}

//是否正确执行搜索功能

@Test

public void test1() throws InterruptedException{

driver.get("");

driver.submit("id$kw","搜索selenium",10,"selenium");

driver.assertContains("selenium", driver.getTitle(), "判断title中是否含有selenium");

Thread.sleep(3000);

}

//搜索selenium点击第一条结果并判断title是否等于预期值

@Test

public void test2() throws InterruptedException{

driver.get("");

driver.submit("id$kw","搜索selenium",10,"selenium");

driver.click("//div[@id='1']/h3/a[1]");

driver.switchToWindow(2);

driver.assertEquals("Selenium - Web Browser Automation", driver.getTitle(), "title是否等于预期");

Thread.sleep(3000);

}

@AfterMethod

public void quit(){

driver.quit();

}

}

更多推荐

java分装

本文发布于:2024-03-06 08:18:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1714826.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!