Merge branch 'featrue/20201205-数据库工具V1.0' of https://gitee.com/pyqone/autest.git into featrue/20201205-数据库工具V1.0

This commit is contained in:
彭宇琦 2020-12-13 15:41:10 +08:00
commit f855430bc8
78 changed files with 234 additions and 3844 deletions

34
pom.xml
View File

@ -13,6 +13,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- 编译编码 -->
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>
<dependencies>
@ -159,10 +161,42 @@
<build>
<plugins>
<!-- 生成javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<aggregate>true</aggregate>
<!-- 生成文件路径 -->
<!--<reportOutputDirectory>./javadocs</reportOutputDirectory>
<destDir>easy-delivery</destDir> -->
<doclint>none</doclint>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 生成sources源码包的插件 -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@ -0,0 +1,58 @@
package pres.auxiliary.tool.sql;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* <p><b>文件名</b>AbstractSql.java</p>
* <p><b>用途</b>
* 数据库工具基类定义工具需要实现的基本方法以及通用方法
* </p>
* <p><b>编码时间</b>2020年12月7日上午8:12:04</p>
* <p><b>修改时间</b>2020年12月7日上午8:12:04</p>
* @author 彭宇琦
* @version Ver1.0
* @since JDK 1.8
*
*/
public class AbstractSql {
/**
* 存储需要执行的SQL语句
*/
StringBuilder sqlText = new StringBuilder("");
/**
* 数据库连接类对象
*/
protected Connection connect;
protected Statement statement;
protected PreparedStatement preState;
/**
* 用于返回当前需要执行的Sql语句
* @return 需要执行的Sql语句
*/
public String getSql() {
return sqlText.toString();
}
/**
* 用于执行存储SQL并返回结果集({@link ResultSet})对象
* @return {@link ResultSet}对象
*/
public ResultSet run() {
try {
return connect.prepareStatement(sqlText.toString()).executeQuery();
} catch (SQLException e) {
throw new DatabaseException(String.format("SQL无法执行。\nSQL:%s", sqlText.toString()));
}
}
@Override
public String toString() {
return getSql();
}
}

View File

@ -0,0 +1,37 @@
package pres.auxiliary.tool.sql;
/**
* <p><b>文件名</b>DatabaseException.java</p>
* <p><b>用途</b>
* 数据库链接有误时抛出的异常
* </p>
* <p><b>编码时间</b>2020年12月7日上午8:28:45</p>
* <p><b>修改时间</b>2020年12月7日上午8:28:45</p>
* @author 彭宇琦
* @version Ver1.0
* @since JDK 1.8
*
*/
public class DatabaseException extends RuntimeException {
private static final long serialVersionUID = 1L;
public DatabaseException() {
}
public DatabaseException(String message) {
super(message);
}
public DatabaseException(Throwable cause) {
super(cause);
}
public DatabaseException(String message, Throwable cause) {
super(message, cause);
}
public DatabaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -0,0 +1,75 @@
package pres.auxiliary.tool.sql;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Properties;
import oracle.jdbc.driver.OracleDriver;
/**
* <p><b>文件名</b>OracleSql.java</p>
* <p><b>用途</b>
* 提供对Oracle数据进行基本的操作
* </p>
* <p><b>编码时间</b>2020年12月7日上午8:13:20</p>
* <p><b>修改时间</b>2020年12月7日上午8:13:20</p>
* @author 彭宇琦
* @version Ver1.0
* @since JDK 1.8
*
*/
public class OracleSql extends AbstractSql {
/**
* 构造方法用于指定数据库基本信息
* @param username 用户名
* @param password 密码
* @param host 主机包括端口默认为1521
* @param dataBase 数据源
*/
public OracleSql(String username, String password, String host, String dataBase) {
//定义数据库对象若驱动不存在时则抛出异常
Driver driver = new OracleDriver();
try {
DriverManager.deregisterDriver(driver);
} catch (SQLException e) {
throw new DatabaseException("ojdbc驱动不存在或驱动有误无法连接Oracle数据库", e);
}
// 添加用户名与密码连接数据库若数据连接有误则抛出异常
Properties pro = new Properties();
pro.put("user", username);
pro.put("password", password);
String url = "jdbc:oracle:thin:@" + host + ":" + dataBase;
try {
connect = driver.connect(url, pro);
} catch (SQLException e) {
throw new DatabaseException(String.format("Oracle数据库连接异常连接信息\n用户名%s\n密码%s\n连接url%s", username, password, url), e);
}
}
public OracleSql type() {
return this;
}
/**
* 用于查找指定表名的数据可指定输出的字段
* @param tableName 表名
* @param fieldNames 字段名
*/
public OracleSql find(String tableName, String...fieldNames) {
sqlText.append("SELECT ");
//添加字段名
sqlText.append("");
sqlText.append(" ");
sqlText.append("FROM ");
sqlText.append(tableName);
return this;
}
}

View File

@ -0,0 +1,10 @@
package pres.auxiliary.tool.sql;
public enum SqlType {
SELECT,
INSERT,
DELECT,
TRUNCATE,
UPDATE;
}

View File

@ -257,6 +257,11 @@ public abstract class AbstractBy {
* @return {@link WebElement}类对象{@link List}集合
*/
protected List<WebElement> recognitionElement(ElementData elementData) {
//判断是否需要自动切换窗体若需要则对元素窗体进行切换
if (isAutoSwitchIframe) {
autoSwitchFrame(elementData.getIframeNameList());
}
//获取元素的定位类型及定位内容
ArrayList<ByType> elementByTypeList = elementData.getByTypeList();
ArrayList<String> elementValueList = elementData.getValueList();

View File

@ -40,11 +40,6 @@ public class CommonBy extends AbstractBy {
elementData = new ElementData(elementName, read);
elementData.addLinkWord(linkKeys);
//判断是否需要自动切换窗体若需要则对元素窗体进行切换
if (isAutoSwitchIframe) {
autoSwitchFrame(elementData.getIframeNameList());
}
//获取元素数据在页面上对应的一组元素若无法查到元素则记录elementList为null
try {
elementList = recognitionElement(elementData);

View File

@ -1,6 +1,9 @@
package pres.auxiliary.work.selenium.element;
import java.util.ArrayList;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebElement;
/**
@ -94,10 +97,15 @@ public class Element {
* 重新根据元素信息在页面查找元素
*/
public int againFindElement() {
//重新拉取元素
abstractBy.elementList = abstractBy.recognitionElement(elementData);
//切换当前读取的元素信息
abstractBy.elementData = elementData;
//重新拉取元素数据在页面上对应的一组元素若无法查到元素则记录elementList为null
try {
abstractBy.elementList = abstractBy.recognitionElement(elementData);
} catch (TimeoutException e) {
abstractBy.elementList = new ArrayList<>();
}
return abstractBy.elementList.size();
}

View File

@ -64,11 +64,6 @@ public abstract class MultiBy<T extends MultiBy<T>> extends AbstractBy {
elementData = new ElementData(elementName, read);
elementData.addLinkWord(linkKeys);
//判断是否需要自动切换窗体若需要则对元素窗体进行切换
if (isAutoSwitchIframe) {
autoSwitchFrame(elementData.getIframeNameList());
}
//获取元素数据在页面上对应的一组元素若无法查到元素则记录elementList为null
try {
elementList = recognitionElement(elementData);

View File

@ -68,7 +68,7 @@ public class WaitEvent extends AbstractEvent{
//调用isDisplayed()方法判断元素是否存在
try {
return !element.getWebElement().isDisplayed();
} catch (NoSuchElementException e) {
} catch (NoSuchElementException | TimeoutException e) {
//若在调用获取页面元素时抛出NoSuchElementException异常则说明元素本身不存在则直接返回true
return true;
} catch (StaleElementReferenceException e) {

View File

@ -1,141 +0,0 @@
package pres.auxiliary.testcase.writecase;
import java.io.File;
import java.io.IOException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import pres.auxiliary.work.old.testcase.change.Tab;
import pres.auxiliary.work.old.testcase.templet.ZentaoTemplet;
import pres.auxiliary.work.old.testcase.writecase.AddInformation;
import pres.auxiliary.work.old.testcase.writecase.FileType;
import pres.auxiliary.work.old.testcase.writecase.InputType;
import pres.auxiliary.work.old.testcase.writecase.PhoneType;
import pres.auxiliary.work.old.testcase.writecase.PresetCase;
public class TestAddInformation {
static PresetCase pc;
static AddInformation a;
@BeforeClass
public void createTemplet() throws Exception {
ZentaoTemplet.setCoverFile(true);
ZentaoTemplet.create();
pc = new PresetCase();
a = new AddInformation();
a.setButtonName("提交");
a.setFailExpectation("失败");
a.setSuccessExpectation("成功");
a.setInformationName("测试");
pc.getAddInformation().setButtonName("提交");
pc.getAddInformation().setFailExpectation("失败");
pc.getAddInformation().setSuccessExpectation("成功");
pc.getAddInformation().setInformationName("测试");
pc.setModule("测试");
a.setModule("测试");
}
@AfterClass
public static void openFolder() throws IOException {
java.awt.Desktop.getDesktop().open(new File(ZentaoTemplet.getSavePath() + "/" + ZentaoTemplet.getFileName() + ".xlsx"));
}
@Test
public void testAddTextboxCase() throws IOException {
pc.getAddInformation().addTextboxCase("苹果", true, true, new char[] {InputType.CH, InputType.EN}, new int[] {5, 10}, null);
a.addTextboxCase("安卓", false, false, null, null, new int[] {5, 10});
pc.getAddInformation().addTextboxCase("苹果", true, false, new char[] {InputType.EN}, new int[] {5}, null);
a.addTextboxCase("安卓", false, true, null, null, new int[] {10});
pc.getAddInformation().addTextboxCase("苹果", true, false, new char[] {InputType.EN}, new int[] {5, pc.getAddInformation().NUM_NAN}, null);
a.addTextboxCase("安卓", false, true, null, null, new int[] {10, pc.getAddInformation().NUM_NAN});
pc.getAddInformation().addTextboxCase("苹果", true, false, new char[] {InputType.EN}, new int[] {pc.getAddInformation().NUM_NAN, 5}, null);
a.addTextboxCase("安卓", false, true, null, null, new int[] {pc.getAddInformation().NUM_NAN, 10});
}
@Test
public void testAddSelectboxCase() throws IOException {
pc.getAddInformation().addSelectboxCase("苹果", true);
a.addSelectboxCase("安卓", false);
}
@Test
public void testAddRadioButtonCase() throws IOException {
pc.getAddInformation().addRadioButtonCase("苹果", true);
a.addRadioButtonCase("安卓", false);
}
@Test
public void testAddCheckboxCase() throws IOException {
pc.getAddInformation().addCheckboxCase("苹果", true);
a.addCheckboxCase("安卓", false);
}
@Test
public void testAddDateCase() throws IOException {
pc.getAddInformation().addDateCase("苹果", true, false);
a.addDateCase("安卓", false, true);
}
@Test
public void testAddStartDateCase() throws IOException {
pc.getAddInformation().addStartDateCase("苹果", true, false, "结束时间");
a.addStartDateCase("安卓", false, true, "活动结束时间");
}
@Test
public void teseAddEndDateCase() throws IOException {
pc.getAddInformation().addEndDateCase("苹果", true, false, "开始时间");
a.addEndDateCase("安卓", false, true, "活动开始时间");
}
@Test
public void teseAddPhoneCase() throws IOException {
pc.getAddInformation().addPhoneCase("苹果", true, false, PhoneType.FIXED);
a.addPhoneCase("卡车", false, true, PhoneType.MOBLE).setRowColorTab(Tab.BLUE);
}
@Test
public void teseAddIDCardCase() throws IOException {
pc.getAddInformation().addIDCardCase("飞机证件", true, false).setRowColorTab(Tab.BLUE);
a.addIDCardCase("汽车", false, true).setRowColorTab(Tab.BLUE);
}
@Test
public void teseAddUploadImageCase() throws IOException {
pc.getAddInformation().addUploadImageCase("苹果", true, true, true, true, true, new char[] {FileType.BMP, FileType.JPG}, new int[] {10});
a.addUploadImageCase("安卓", true, true, true, true, true, null, null);
pc.getAddInformation().addUploadImageCase("苹果", true, true, true, true, true, new char[] {FileType.BMP, FileType.JPG}, new int[] {10, 12});
a.addUploadImageCase("安卓", true, true, true, true, true, null, new int[] {10, a.NUM_NAN});
}
@Test
public void teseAddUploadImageCase_2() throws IOException {
pc.getAddInformation().addUploadImageCase("苹果", true, true, true, true, true, new char[] {FileType.BMP, FileType.JPG}, new int[] {10});
}
@Test
public void teseAddUploadFileCase() throws IOException {
pc.getAddInformation().addUploadFileCase("苹果", true, true, true, new char[] {FileType.DOC, FileType.XLS}, new int[] {10});
a.addUploadFileCase("安卓", true, true, true, null, null);
pc.getAddInformation().addUploadFileCase("苹果", true, true, true, new char[] {FileType.DOCX, FileType.TXT}, new int[] {10, 12});
a.addUploadFileCase("安卓", true, true, true, null, new int[] {10, a.NUM_NAN});
}
@Test
public void teseAdd_Un_WholeInformationCase() throws IOException {
pc.getAddInformation().addUnWholeInformationCase();
a.addUnWholeInformationCase();
pc.getAddInformation().addWholeInformationCase();
a.addWholeInformationCase();
}
}

View File

@ -1,94 +0,0 @@
package pres.auxiliary.testcase.writecase;
import java.io.File;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import pres.auxiliary.work.old.testcase.templet.ZentaoTemplet;
import pres.auxiliary.work.old.testcase.writecase.BrowseList;
import pres.auxiliary.work.old.testcase.writecase.PresetCase;
public class TestBrowseList {
static PresetCase pc;
static BrowseList b;
@BeforeClass
public static void createTemplet() {
ZentaoTemplet.setCoverFile(true);
ZentaoTemplet.create();
pc = new PresetCase();
b = new BrowseList();
pc.setModule("测试");
}
@AfterClass
public static void openFolder() throws IOException {
java.awt.Desktop.getDesktop().open(new File(ZentaoTemplet.getSavePath() + "/" + ZentaoTemplet.getFileName() + ".xlsx"));
}
@Test
public void testAddAppBrowseListCase() throws IOException {
pc.getBrowseList().addAppBrowseListCase("苹果");
b.addAppBrowseListCase("安卓");
}
@Test
public void testAddWebBrowseListCase() throws IOException {
pc.getBrowseList().addWebBrowseListCase("苹果");
b.addWebBrowseListCase("安卓");
}
@Test
public void testAddInputSearchCase() throws IOException {
pc.getBrowseList().addInputSearchCase("型号", "苹果");
b.addInputSearchCase("型号", "安卓");
}
@Test
public void testAddSelectSearchCase() throws IOException {
pc.getBrowseList().addSelectSearchCase("型号", "苹果");
b.addSelectSearchCase("型号", "安卓");
}
@Test
public void testAddDateSearchCase() throws IOException {
pc.getBrowseList().addDateSearchCase("开始时间", true, "苹果");
b.addDateSearchCase("结束时间", false, "安卓");
}
@Test
public void testAddListSortCase() throws IOException {
pc.getBrowseList().addListSortCase("生产日期", "苹果");
b.addListSortCase("生产日期", "安卓");
}
@Test
public void testAddExportListCase() throws IOException {
pc.getBrowseList().addExportListCase("苹果", true);
b.addExportListCase("安卓", false);
}
@Test
public void testAddImportListCase() throws IOException {
pc.getBrowseList().addImportListCase("苹果");
b.addImportListCase("安卓");
}
@Test
public void testAddResetSearchCase() throws IOException {
pc.getBrowseList().addResetSearchCase();
b.addResetSearchCase();
}
@Test
public void testAddSwitchListShowDataCase() throws IOException {
pc.getBrowseList().addSwitchListShowDataCase();
b.addSwitchListShowDataCase();
}
}

View File

@ -1,64 +0,0 @@
package pres.auxiliary.testcase.writecase;
import java.io.File;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import pres.auxiliary.work.old.testcase.templet.ZentaoTemplet;
import pres.auxiliary.work.old.testcase.writecase.Map;
import pres.auxiliary.work.old.testcase.writecase.PresetCase;
public class TestMap {
static PresetCase pc;
static Map m;
@BeforeClass
public static void createTemplet() {
ZentaoTemplet.setCoverFile(true);
ZentaoTemplet.create();
pc = new PresetCase();
m = new Map();
pc.setModule("测试");
}
@AfterClass
public static void openFolder() throws IOException {
java.awt.Desktop.getDesktop().open(new File(ZentaoTemplet.getSavePath() + "/" + ZentaoTemplet.getFileName() + ".xlsx"));
}
@Test
public void testAddRangeFindingCase() throws IOException {
pc.getMap().addRangeFindingCase();
m.addRangeFindingCase();
}
@Test
public void testAddMapPointCase() throws IOException {
pc.getMap().addMapPointCase("小车");
m.addMapPointCase("卡车");
}
@Test
public void testAddMapSearchInformationCase() throws IOException {
pc.getMap().addMapSearchInformationCase("车牌", "小车");
m.addMapSearchInformationCase("车牌", "卡车");
}
@Test
public void testAddCarLocusPlaybackCase() throws IOException {
pc.getMap().addCarLocusPlaybackCase();
m.addCarLocusPlaybackCase();
}
@Test
public void testAddShowLocusCase() throws IOException {
pc.getMap().addShowLocusCase("小车", "打车");
m.addShowLocusCase("公交");
}
}

View File

@ -1,88 +0,0 @@
package pres.auxiliary.testcase.writecase;
import java.io.File;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import pres.auxiliary.work.old.testcase.templet.ZentaoTemplet;
import pres.auxiliary.work.old.testcase.writecase.PresetCase;
import pres.auxiliary.work.old.testcase.writecase.Username;
public class TestUsername {
static PresetCase pc;
static Username m;
@BeforeClass
public static void createTemplet() {
ZentaoTemplet.setCoverFile(true);
ZentaoTemplet.create();
pc = new PresetCase();
m = new Username();
pc.setModule("测试");
}
@AfterClass
public static void openFolder() throws IOException {
java.awt.Desktop.getDesktop().open(new File(ZentaoTemplet.getSavePath() + "/" + ZentaoTemplet.getFileName() + ".xlsx"));
}
@Test
public void testAddRightLoginCase() throws IOException {
pc.getUsername().addRightLoginCase();
m.addRightLoginCase();
}
@Test
public void testAddErrorLoginCase() throws IOException {
pc.getUsername().addErrorLoginCase();
m.addErrorLoginCase();
}
@Test
public void testAddCaptchaCase() throws IOException {
pc.getUsername().addCaptchaCase();
m.addCaptchaCase();
}
@Test
public void testAddLoginAuthorityCase() throws IOException {
pc.getUsername().addLoginAuthorityCase(true);
m.addLoginAuthorityCase(false);
}
@Test
public void testAddUsernameRegisterCase() throws IOException {
pc.getUsername().addUsernameRegisterCase(true);
m.addUsernameRegisterCase(false);
}
@Test
public void testAddUsernameForgetCase() throws IOException {
pc.getUsername().addUsernameForgetCase();
m.addUsernameForgetCase();
}
@Test
public void testAddPasswordRegisterOrForgetCase() throws IOException {
pc.getUsername().addPasswordRegisterOrForgetCase("注册");
m.addPasswordRegisterOrForgetCase("忘记密码");
}
@Test
public void testAddCodeRegisterOrForgetCase() throws IOException {
pc.getUsername().addCodeRegisterOrForgetCase("注册", true);
m.addCodeRegisterOrForgetCase("忘记密码", false);
}
@Test
public void testAddAlterPasswordCase() throws IOException {
pc.getUsername().addAlterPasswordCase();
m.addAlterPasswordCase();
}
}

View File

@ -1,73 +0,0 @@
package pres.auxiliary.testcase.writecase;
import java.io.File;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import pres.auxiliary.work.old.testcase.templet.ZentaoTemplet;
import pres.auxiliary.work.old.testcase.writecase.PresetCase;
import pres.auxiliary.work.old.testcase.writecase.Video;
public class TestVideo {
static PresetCase pc;
static Video m;
@BeforeClass
public static void createTemplet() throws IOException {
ZentaoTemplet.setCoverFile(true);
ZentaoTemplet.create();
pc = new PresetCase();
m = new Video();
pc.setModule("测试");
pc.getVideo().setVideoType("电影");
m.setVideoType("电视剧");
}
@AfterClass
public static void openFolder() throws IOException {
java.awt.Desktop.getDesktop().open(new File(ZentaoTemplet.getSavePath() + "/" + ZentaoTemplet.getFileName() + ".xlsx"));
}
@Test
public void testAddPlayVideoCase() throws IOException {
pc.getVideo().addPlayVideoCase(true);
m.addPlayVideoCase(false);
}
@Test
public void testAddVideoScreenshotCase() throws IOException {
pc.getVideo().addVideoScreenshotCase();
m.addVideoScreenshotCase();
}
@Test
public void testAddVideoAdvanceCase() throws IOException {
pc.getVideo().addVideoAdvanceCase(true, true);
m.addVideoAdvanceCase(false, false);
}
@Test
public void testAddVideoSpeedCase() throws IOException {
pc.getVideo().addVideoSpeedCase(true);
m.addVideoSpeedCase(false);
}
@Test
public void testAddVideoProgressBarCase() throws IOException {
pc.getVideo().addVideoProgressBarCase();
m.addVideoProgressBarCase();
}
@Test
public void testAddFullScreenPlayCase() throws IOException {
pc.getVideo().addFullScreenPlayCase();
m.addFullScreenPlayCase();
}
}

View File

@ -0,0 +1 @@
/sql/

View File

@ -101,32 +101,6 @@ public class TimeTest {
System.out.println("----------------------------");
}
/**
* 测试{@link Time#getFormatTime(String)}
*/
@Test
public void getFormatTimeTest_String() {
time.setNowTime();
System.out.println(time.getFormatTime("yyyy-MM-dd HH:mm:ss"));
System.out.println("----------------------------");
time.setTime("2019/12/04 03:03:20");
System.out.println(time.getFormatTime("yyyy-MM-dd HH:mm:ss"));
System.out.println("----------------------------");
time.setTime(new Date());
System.out.println(time.getFormatTime("yyyy-MM-dd HH:mm:ss"));
System.out.println("----------------------------");
time.setTime(1576037076297L);
System.out.println(time.getFormatTime("yyyy-MM-dd HH:mm:ss"));
System.out.println(time.getFormatTime("2019/12/04 03:03:20"));
System.out.println("----------------------------");
time.setTime("2019/12/04");
System.out.println(time.getFormatTime("yyyy-MM-dd HH:mm:ss"));
System.out.println("----------------------------");
time.setTime("03:03:20");
System.out.println(time.getFormatTime("yyyy-MM-dd HH:mm:ss"));
System.out.println("----------------------------");
}
/**
* 测试{@link Time#addTime(String)}
*/

View File

@ -1,99 +0,0 @@
package pres.auxiliary.work.selenium.element;
import java.io.File;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import pres.auxiliary.work.selenium.brower.ChromeBrower;
import pres.auxiliary.work.selenium.brower.ChromeBrower.ChromeOptionType;
/**
* <p><b>文件名</b>CommonElementTest.java</p>
* <p><b>用途</b>
* {@link CommonBy}类方法进行单元测试
* </p>
* <p><b>测试对象</b>桂建通工资管理的工资单管理模块获取第一条数据的单位信息</p>
* <p><b>编码时间</b>2020年4月30日上午7:44:34</p>
* <p><b>修改时间</b>2020年4月30日上午7:44:34</p>
* @author
* @version Ver1.0
* @since JDK 12
*
*/
public class CommonByTest {
ChromeBrower cb = new ChromeBrower(new File("Resource/BrowersDriver/Chrom/78.0394.70/chromedriver.exe"));
CommonBy ce;
@BeforeClass
public void initDate() {
cb.addConfig(ChromeOptionType.CONTRAL_OPEN_BROWER, "127.0.0.1:9222");
ce = new CommonBy(cb);
}
@AfterClass
public void qiut() {
cb.getDriver().quit();
}
/**
* 用于测试非xml文件中的传参进行窗体切换与元素的获取
*/
@Test
public void getCommonElementTest() {
ce.switchFrame("//iframe[contains(@src, '/Regulatory/admin/index.jsp')]");
ce.switchFrame("//iframe[contains(@src, '工资单管理')]");
System.out.println(ce.getElement("//*[@id=\"listBox\"]/li[1]/div[1]/p/span[1]").getWebElement().getText());
}
/**
* 用于测试xml文件中的传参进行窗体切换与元素的获取
*/
@Test
public void getXmlElementTest() {
File xmlFile = new File("src/test/java/pres/auxiliary/work/selenium/element/测试文件.xml");
ce.setXmlFile(xmlFile, false);
ce.setAutoSwitchIframe(false);
ce.switchFrame("主窗体");
ce.switchFrame("工资发放详情");
System.out.println(ce.getElement("单位名称").getWebElement().getText());
}
/**
* 用于测试xml文件的自动定位窗体
*/
@Test
public void autoLocationElementTest() {
File xmlFile = new File("src/test/java/pres/auxiliary/work/selenium/element/测试文件.xml");
ce.setXmlFile(xmlFile, false);
System.out.println(ce.getElement("单位名称").getWebElement().getText());
DataListBy d = new DataListBy(ce);
d.add("单位名称");
System.out.println(d.getElement("单位名称", 1).getWebElement().getText());
}
/**
* 用于测试xml文件的多次切换窗体后自动定位窗体
*/
@Test
public void exceptAutoLocationElementTest() {
File xmlFile = new File("src/test/java/pres/auxiliary/work/selenium/element/测试文件.xml");
ce.setXmlFile(xmlFile);
//先切主窗体
ce.switchFrame("主窗体");
//在获取元素前会判断元素所在窗体由于主窗体是爷爷辈窗体获取元素前会切换工资发放详情窗体
System.out.println(ce.getElement("单位名称").getWebElement().getText());
}
/**
* 用于测试外链xml
*/
@Test
public void getElementTest() {
File xmlFile = new File("src/test/java/pres/auxiliary/work/selenium/element/测试文件.xml");
ce.setXmlFile(xmlFile);
System.out.println(ce.getElement("搜索条件", "工资单编号").getWebElement().getAttribute("type"));
}
}

View File

@ -1,117 +0,0 @@
package pres.auxiliary.work.selenium.element;
import java.io.File;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import pres.auxiliary.work.selenium.location.AbstractLocation;
import pres.auxiliary.work.selenium.location.XmlLocation;
/**
* <p><b>文件名</b>ElementDataTest.java</p>
* <p><b>用途</b>
* {@link ElementData}类进行单元测试
* </p>
* <p><b>编码时间</b>2020年10月12日上午8:47:14</p>
* <p><b>修改时间</b>2020年10月12日上午8:47:14</p>
* @author 彭宇琦
* @version Ver1.0
*
*/
public class ElementDataTest {
AbstractLocation ar;
ElementData test;
final File XML_FILE = new File("src/test/java/pres/auxiliary/work/selenium/element/测试用xml文件.xml");
@BeforeClass
public void init() {
ar = new XmlLocation(XML_FILE);
}
@BeforeMethod
public void addElement() {
test = new ElementData("XX控件6", ar);
}
/**
* 用于测试{@link ElementData#getName()}方法<br>
* 预期<br>
* XX控件6
*/
@Test
public void getNameTest() {
System.out.println(test.getName());
}
/**
* 用于测试{@link ElementData#getByTypeList()}方法<br>
* 预期<br>
* XPATH<br>
* CSS<br>
* XPATH
*/
@Test
public void getByTypeListTest() {
test.getByTypeList().forEach(System.out :: println);
}
/**
* 用于测试{@link ElementData#getValueList()}方法<br>
* 预期<br>
* //XXX控件6[@X='XXXX']<br>
* http body ${tagName}<br>
* //XXX模板控件1[@X='${src}']/div[@name='XXX控件6']/div[@is='test' and text()='${src}']/span[text()='${str2}']/span[id='${aaaa}']
*/
@Test
public void getValueListTest() {
test.getValueList().forEach(System.out :: println);
}
/**
* 用于测试{@link ElementData#getElementType()}方法<br>
* 预期<br>
* COMMON_ELEMENT
*/
@Test
public void getElementTypeTest() {
System.out.println(test.getElementType());
}
/**
* 用于测试{@link ElementData#getIframeNameList()}方法<br>
* 预期<br>
* 窗体1<br>
* 窗体1.1<br>
* 窗体1.1.1
*/
@Test
public void getIframeNameListTest() {
test.getIframeNameList().forEach(System.out :: println);
}
/**
* 用于测试{@link ElementData#getWaitTime()}方法<br>
* 预期<br>
* -1
*/
@Test
public void getWaitTimeTest() {
System.out.println(test.getWaitTime());
}
/**
* 用于测试{@link ElementData#addLinkWord(String...)}方法<br>
* 预期<br>
* //XXX控件6[@X='XXXX']<br>
* http body 外链1<br>
* //XXX模板控件1[@X='外链1']/div[@name='XXX控件6']/div[@is='test' and text()='外链2']/span[text()='外链3']/span[id='${aaaa}']
*/
@Test
public void addLinkWordTest() {
test.addLinkWord("外链1", "外链2", "外链3");
test.getValueList().forEach(System.out :: println);
}
}

View File

@ -1,89 +0,0 @@
package pres.auxiliary.work.selenium.element;
import java.io.File;
import java.util.ArrayList;
import org.openqa.selenium.By;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import pres.auxiliary.work.selenium.brower.ChromeBrower;
import pres.auxiliary.work.selenium.brower.ChromeBrower.ChromeOptionType;
public class ElementTest {
/**
* 主窗体元素
*/
Element mainFrameElement;
/**
* 工资发放详情窗体元素
*/
Element payrollFrameElement;
/**
* 单位名称元素
*/
Element comNameElement;
/**
* 专户名称元素
*/
Element payrollElement;
/**
* 标题元素
*/
Element titleElement;
ChromeBrower cb;
@BeforeClass
public void init() {
cb = new ChromeBrower(new File("Resource/BrowersDriver/Chrom/78.0394.70/chromedriver.exe"));
cb.addConfig(ChromeOptionType.CONTRAL_OPEN_BROWER, "127.0.0.1:9222");
ArrayList<By> mainFrameByList = new ArrayList<By>();
mainFrameByList.add(By.xpath("//iframe[contains(@src,'/Regulatory/admin/index.jsp')]"));
mainFrameElement = new Element(cb, "主窗体元素", ElementType.COMMON_ELEMENT, 0);
mainFrameElement.setByList(mainFrameByList);
ArrayList<By> payrollFrameByList = new ArrayList<By>();
payrollFrameByList.add(By.xpath("//iframe[contains(@src,'工资单管理')]"));
payrollFrameElement = new Element(cb, "工资发放详情窗体元素", ElementType.COMMON_ELEMENT, 0);
payrollFrameElement.setByList(payrollFrameByList);
payrollFrameElement.setIframeElement(mainFrameElement);
ArrayList<By> comNameByList = new ArrayList<By>();
comNameByList.add(By.xpath("//*[@id='listBox']/li[1]/div[1]/p/span[1]"));
comNameElement = new Element(cb, "单位名称元素", ElementType.COMMON_ELEMENT, 0);
comNameElement.setByList(comNameByList);
comNameElement.setIframeElement(payrollFrameElement);
ArrayList<By> payrollByList = new ArrayList<By>();
payrollByList.add(By.xpath("//*[@class='pay-code']"));
payrollElement = new Element(cb, "专户名称元素", ElementType.COMMON_ELEMENT, 0);
payrollElement.setByList(payrollByList);
payrollElement.setIframeElement(payrollFrameElement);
ArrayList<By> titleByList = new ArrayList<By>();
titleByList.add(By.xpath("//*[@lay-id='工资单管理']"));
titleElement = new Element(cb, "标题元素", ElementType.COMMON_ELEMENT, 0);
titleElement.setByList(titleByList);
titleElement.setIframeElement(mainFrameElement);
}
@AfterClass
public void closeDriver() {
cb.getDriver().quit();
}
@Test
public void getWebElementTest() {
System.out.println(comNameElement.getWebElement().getText());
System.out.println("----------------------------------------");
System.out.println(payrollElement.getWebElement().getText());
System.out.println("----------------------------------------");
System.out.println(titleElement.getWebElement().getText());
System.out.println("----------------------------------------");
System.out.println(payrollElement.getWebElement().getText());
}
}

View File

@ -1,91 +0,0 @@
package pres.auxiliary.work.selenium.element;
import java.io.File;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import pres.auxiliary.work.selenium.brower.ChromeBrower;
import pres.auxiliary.work.selenium.brower.ChromeBrower.ChromeOptionType;
import pres.auxiliary.work.selenium.event.ClickEvent;
/**
* <p><b>文件名</b>SelectByText.java</p>
* <p><b>用途</b>
* {@link SelectBy_Old}类进行测试
* </p>
* <p><b>页面</b>
* 对标准型下拉选项测试页面为jira提BUG弹窗对非标准型下拉为运营系统测试环境消息推送管理页面
* </p>
* <p><b>编码时间</b>2020年5月23日下午4:29:10</p>
* <p><b>修改时间</b>2020年5月23日下午4:29:10</p>
* @author 彭宇琦
* @version Ver1.0
* @since JDK 12
*
*/
public class SelectByTest {
ChromeBrower cb = new ChromeBrower(new File("Resource/BrowersDriver/Chrom/78.0394.70/chromedriver.exe"));
SelectBy_Old s;
CommonBy_Old cby;
ClickEvent ce;
@BeforeClass(alwaysRun = true)
public void init() {
cb.addConfig(ChromeOptionType.CONTRAL_OPEN_BROWER, "127.0.0.1:9222");
s = new SelectBy_Old(cb);
cby = new CommonBy_Old(cb);
ce = new ClickEvent(cb.getDriver());
}
@AfterClass(alwaysRun = true)
public void quit() {
cb.getDriver().quit();
}
/**
* 用于测试选择非标准型下拉选项
* @throws InterruptedException
*/
@Test(groups = "list")
public void changeElement_List() throws InterruptedException {
Element_Old e = cby.getElement("/html/body/div[1]/div/div/section/div/div[1]/div[4]/div[1]/input");
ce.click(e);
s.add("/html/body/div/div/div[1]/ul/li/span");
//按照下标进行选择(第三个选项待审核)
ce.click(s.getElement(3));
Thread.sleep(2000);
ce.click(e);
//按照文本进行选择
ce.click(s.getElement("审核通过"));
}
/**
* 测试标准型拉下选项的选择
* @throws InterruptedException
*/
@Test(groups = "commom")
public void addTest_Common() throws InterruptedException {
s.add("//label[text()='严重等级']/../select");
//按照下标进行选择(第三个选项轻微)
ce.click(s.getElement(3));
Thread.sleep(2000);
//按照文本进行选择
ce.click(s.getElement("致命"));
s.add("//label[text()='缺陷来源']/../select");
//按照下标进行选择(第三个选项与需求不一致)
ce.click(s.getElement(3));
//点击修复版本未排期的第5个选项
ce.click(cby.getElement("//*[@id=\"fixVersions-multi-select\"]/span"));
s.add("//div[contains(@class, 'ajs-layer box')]//*[text()='20200408-解决实名制平台响应慢问题']/../..//a");
// ce.click(s.getElement("2020", "-", "银行接口"));
ce.click(s.getElement("233", "-", "银行接口"));
}
}

View File

@ -1,110 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="">
<templet>
<xpath id='1'>//XXX模板控件1[@X='${name}']/div/div[@${att}='${id}']/input</xpath>
<css id='2'>http body ${tagName}</css>
<xpath id='3'>//XXX模板控件1[@X='${src}']/div[@name='${name}']</xpath>
<xpath id='4'>//XXX模板控件1[@X='${src}']/div[@name='${name}']/div[@is='${str1}' and text()='${str1}']</xpath>
<xpath id='5'>//XXX模板控件1[@X='${src}']/div[@name='${name}']/div[@is='${str1}' and text()='${src}']/span[text()='${str2}']/span[id='${aaaa}']</xpath>
<id id='6'>${name}</id>
</templet>
<element name='XX控件1'>
<xpath is_use='true'>//XX控件1[@X='XXXX']</xpath>
</element>
<iframe name='窗体1' >
<xpath is_use='true'>//窗体1[@X='XXXX']</xpath>
<css temp_id='2' tagName='iframe'/>
<element name='XX控件2'>
<xpath is_use='true'>//XX控件2[@X='XXXX']</xpath>
</element>
<element name='XX控件3'>
<xpath is_use='true'>//XXX控件3[@X='XXXX']</xpath>
</element>
<iframe name='窗体1.1' >
<xpath is_use='true'>//窗体1.1[@X='XXXX']</xpath>
<element name='XX控件4'>
<xpath is_use='true'>//XXX控件4[@X='XXXX']</xpath>
</element>
<element name='XX控件5'>
<xpath is_use='true'>//XXX控件5[@X='XXXX']</xpath>
</element>
<iframe name='窗体1.1.1' >
<xpath is_use='true'>//窗体1.1.1[@X='XXXX']</xpath>
<element name='XX控件6'>
<xpath is_use='true'>//XXX控件6[@X='XXXX']</xpath>
<css temp_id='2'></css>
<xpath temp_id='5' str1='test'></xpath>
</element>
<element name='XX控件7'>
<xpath is_use='true'>//XXX控件7[@X='XXXX']</xpath>
</element>
</iframe>
</iframe>
<iframe name='窗体1.2' >
<xpath is_use='true'>//窗体1.2[@X='XXXX']</xpath>
<element name='XX控件8'>
<xpath is_use='true'>//XXX控件8[@X='XXXX']</xpath>
</element>
<element name='XX控件9'>
<xpath is_use='true'>//XXX控件9[@X='XXXX']</xpath>
</element>
</iframe>
</iframe>
<iframe name='窗体2' >
<xpath is_use='true'>//窗体2[@X='XXXX']</xpath>
<element name='XX控件10'>
<xpath is_use='true'>//XXX控件10[@X='XXXX']</xpath>
</element>
<element name='XX控件11'>
<xpath is_use='true' temp_id='1' id='Test' att='src'/>
<css is_use='true' temp_id='2' tagName='div'/>
<xpath is_use='true' temp_id='3' />
<id temp_id='6' name='测试控件'/>
</element>
<element name='XX控件12'>
<xpath is_use='true' temp_id='3' />
</element>
</iframe>
<iframe name='窗体3' >
<xpath is_use='true'>//窗体3[@X='${ccc}']</xpath>
<element name='XX控件13'>
<xpath is_use='true' temp_id='3' />
</element>
<element name='XX控件14'>
<xpath is_use='true' temp_id='4' />
</element>
<element name='XX控件15' wait='100'>
<xpath is_use='true' temp_id='5' />
</element>
<element name='XX控件16' element_type='0' wait='1'>
<xpath is_use='true' temp_id='1' id='Test' att='src'/>
</element>
<element name='XX控件17' element_type='1' wait='0'>
<xpath is_use='true' temp_id='1' id='Test' att='src'/>
</element>
<element name='XX控件18' element_type='2' wait='-11'>
<xpath is_use='true' temp_id='1' id='Test' att='src'/>
</element>
<element name='XX控件19' element_type='3' wait='ddsf'>
<xpath is_use='true' temp_id='1' id='Test' att='src'/>
</element>
<element name='XX控件20' element_type='3' wait='ddsf'>
<xpath is_use='true' temp_id='测试' id='Test' att='src'/>
</element>
</iframe>
</project>

View File

@ -1,58 +0,0 @@
package pres.auxiliary.work.selenium.event;
import java.io.File;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import pres.auxiliary.work.selenium.brower.ChromeBrower;
import pres.auxiliary.work.selenium.brower.ChromeBrower.ChromeOptionType;
import pres.auxiliary.work.selenium.event.EventProxy.ActionType;
public class EventProxyTest {
EventProxy<ClickEvent> clickProxy;
EventProxy<TextEvent> inputProxy;
ChromeBrower chrome;
CommonBy_Old by;
@BeforeClass
public void init() {
chrome = new ChromeBrower(new File("Resource/BrowersDriver/Chrom/83.0.4103.39/chromedriver.exe"));
chrome.addConfig(ChromeOptionType.CONTRAL_OPEN_BROWER, "127.0.0.1:9222");
clickProxy = new EventProxy<>(new ClickEvent(chrome.getDriver()));
inputProxy = new EventProxy<>(new TextEvent(chrome.getDriver()));
by = new CommonBy_Old(chrome);
}
@AfterClass
public void showResult() {
ClickEvent click = clickProxy.getProxyInstance();
click.doubleClick(by.getElement("//*[text()='登录']"));
}
@Test
public void addAcionTest() {
TextEvent textEvent = new TextEvent(chrome.getDriver());
textEvent.input(by.getElement("//*[@name='account']"), "admin");
textEvent.input(by.getElement("//*[@name='password']"), "1111111");
inputProxy.addAcion(ActionType.FUNCTION_BEFORE, ".*input.*", (info) -> {
inputProxy.getProxyInstance().clear(info.getElement().get(0));
});
clickProxy.addAcion(ActionType.ELEMENT_BEFORE, ".*登录.*", (info) -> {
TextEvent text = inputProxy.getProxyInstance();
text.input(by.getElement("//*[@name='account']"), "admin");
text.input(by.getElement("//*[@name='password']"), "1111111");
});
clickProxy.addAcion(ActionType.ELEMENT_AFTER, ".*登录.*", (info) -> {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
by.alertAccept();
});
}
}

View File

@ -1,84 +0,0 @@
package pres.auxiliary.work.selenium.event;
import java.io.File;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import pres.auxiliary.work.selenium.brower.ChromeBrower;
import pres.auxiliary.work.selenium.brower.ChromeBrower.ChromeOptionType;
/**
* <p><b>文件名</b>EventWaitTest.java</p>
* <p><b>用途</b>
* 用于对{@link WaitEvent}类进行测试
* </p>
* <p><b>页面</b>
* 运维管理系统岗前答题库模块
* </p>
* <p><b>编码时间</b>2020年5月24日下午4:37:25</p>
* <p><b>修改时间</b>2020年5月24日下午4:37:25</p>
* @author
* @version Ver1.0
* @since JDK 12
*
*/
public class EventWaitTest {
WaitEvent wait;
ClickEvent c;
TextEvent t;
CommonBy_Old cby;
ChromeBrower cb = new ChromeBrower(new File("Resource/BrowersDriver/Chrom/78.0394.70/chromedriver.exe"));
@BeforeClass
public void init() {
cb.addConfig(ChromeOptionType.CONTRAL_OPEN_BROWER, "127.0.0.1:9222");
cby = new CommonBy_Old(cb);
c = new ClickEvent(cb.getDriver());
t = new TextEvent(cb.getDriver());
wait = new WaitEvent(cb.getDriver());
}
@AfterClass
public void quit() {
cb.getDriver().quit();
}
/**
* 测试{@link WaitEvent#disappear(pres.auxiliary.work.selenium.element.Element)}方法
*/
@Test
public void disappearTest() {
//获取编号列
DataListBy_Old element = new DataListBy_Old(cb);
element.add("/html/body/div[1]/div/div/section/div/div[2]/div[3]/table//td[contains(@class,'el-table_1_column_1 ')]/div/span");
System.out.println(element.getMinColumnSize());
System.out.println("开始页:");
//获取并打印编号列
for (int i = 1; i <= element.getMinColumnSize(); i++) {
System.out.println("====================================");
for (String name : element.getNames()) {
System.out.println("编号" + t.getText(element.getElement(name, i)));
}
System.out.println("====================================");
}
//点击搜索按钮使其弹出等待加载的图标
c.click(cby.getElement("//button[@class='btn-next']"));
//等待图标消失
wait.disappear(cby.getElement("//*[@class='circular']"));
System.out.println("下一页:");
//重新再获取并打印编号列
for (int i = 1; i <= element.getMinColumnSize(); i++) {
System.out.println("====================================");
for (String name : element.getNames()) {
System.out.println("编号" + "=" + t.getText(element.getElement(name, i)));
}
System.out.println("====================================");
}
}
}

View File

@ -1,104 +0,0 @@
package pres.auxiliary.work.selenium.event;
import java.io.File;
import java.lang.reflect.Method;
import org.openqa.selenium.WebElement;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.alibaba.fastjson.JSONObject;
import pres.auxiliary.work.selenium.brower.ChromeBrower;
import pres.auxiliary.work.selenium.brower.ChromeBrower.ChromeOptionType;
/**
* <p><b>文件名</b>JsEventTest.java</p>
* <p><b>用途</b>
* 用于对{@link JsEvent}类进行单元测试使用控制已打开的浏览器
* </p>
* <p><b>页面</b>
* https://www.baidu.com/百度首页针对搜索条件文本框
* </p>
* <p><b>编码时间</b>2020年5月17日 下午1:40:28</p>
* <p><b>修改时间</b>2020年5月17日 下午1:40:28</p>
* @author 彭宇琦
* @version Ver1.0
* @since JDK 12
*/
public class JsEventTest {
/**
* 输入文本框元素对象
*/
Element_Old inputElemnt;
JsEvent event;
ChromeBrower cb;
/**
* 初始化数据
*/
@BeforeClass
public void init() {
cb = new ChromeBrower(new File("Resource/BrowersDriver/Chrom/78.0394.70/chromedriver.exe"));
cb.addConfig(ChromeOptionType.CONTRAL_OPEN_BROWER, "127.0.0.1:9222");
inputElemnt = new CommonBy_Old(cb).getElement("//*[@id='kw']");
//初始化js类
event = new JsEvent(cb.getDriver());
}
@AfterClass
public void quit() {
cb.getDriver().quit();
}
@BeforeMethod
public void show(Method method) {
System.out.println("================================");
System.out.println(method.getName() + "方法测试结果:");
}
/**
* 测试{@link JsEvent#getAttribute(WebElement, String)}方法
*/
@Test
public void getAttributeTest() {
System.out.println(event.getAttribute(inputElemnt, "class"));
}
/**
* 测试{@link JsEvent#putAttribute(WebElement, String, String)}方法
*/
@Test
public void putAttributeTest() {
System.out.println(event.putAttribute(inputElemnt, "lll", null));
}
/**
* 测试{@link JsEvent#addElement(WebElement, String)}方法
*/
@Test
public void addElementTest_String() {
System.out.println(event.addElement(inputElemnt, "input"));
}
/**
* 测试{@link JsEvent#deleteElement(WebElement)}方法
*/
@Test
public void deleteElementTest() {
System.out.println(event.deleteElement(inputElemnt));
}
/**
* 测试{@link JsEvent#addElement(WebElement, com.alibaba.fastjson.JSONObject)}方法
*/
@Test
public void addElementTest_Json() {
JSONObject json = event.deleteElement(new CommonBy_Old(cb.getDriver()).getElement("//*[@value = '百度一下']"));
Element_Old e = new CommonBy_Old(cb.getDriver()).getElement("//*[text() = '我的关注']");
System.out.println(event.addElement(e, json));
}
}

View File

@ -1,102 +0,0 @@
package pres.auxiliary.work.selenium.event;
import java.io.File;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import pres.auxiliary.work.selenium.brower.ChromeBrower;
import pres.auxiliary.work.selenium.brower.ChromeBrower.ChromeOptionType;
/**
* <p><b>文件名</b>CommonElementTest.java</p>
* <p><b>用途</b>
* {@link TextEvent}类方法进行单元测试
* </p>
* <p><b>测试对象</b>桂建通工资管理的工资单管理模块获取第一条数据的单位信息</p>
* <p><b>编码时间</b>2020年4月30日上午7:44:34</p>
* <p><b>修改时间</b>2020年4月30日上午7:44:34</p>
* @author 彭宇琦
* @version Ver1.0
* @since JDK 12
*
*/
public class TextEventTest {
/**
* 列表上编号列第一个元素
*/
final String FRIST_ID_XPATH = "//*[@class=\"el-table__body-wrapper\"]/table/tbody/tr[1]/td[1]/div/span";
/**
* 列表上编号列所有元素
*/
final String ID_LIST_XPATH = "//*[@class=\"el-table__body-wrapper\"]/table/tbody/tr/td[1]/div/span";
ChromeBrower cb = new ChromeBrower(new File("Resource/BrowersDriver/Chrom/78.0394.70/chromedriver.exe"));
CommonBy_Old ce;
DataListBy_Old dle;
TextEvent t;
Element_Old turningButton;
@BeforeClass
public void init() {
cb.addConfig(ChromeOptionType.CONTRAL_OPEN_BROWER, "127.0.0.1:9222");
ce = new CommonBy_Old(cb.getDriver());
dle = new DataListBy_Old(cb.getDriver());
t = new TextEvent(cb.getDriver());
turningButton = ce.getElement("//i[@class=\"el-icon el-icon-arrow-right\"]");
}
@AfterClass
public void qiut() {
cb.getDriver().quit();
}
@BeforeMethod
public void switchRootFrame() {
ce.switchRootFrame();
}
/**
* 测试普通元素调用{@link TextEvent#getText(pres.auxiliary.work.selenium.element.Element_Old)}方法
* @throws InterruptedException
*/
@Test
public void getTextTest_CommonElement() throws InterruptedException {
System.out.println("第一页:");
System.out.println(t.getText(ce.getElement(FRIST_ID_XPATH)));
//测试元素过期问题
System.out.println("==========================================");
System.out.println("第二页:");
//测试元素过期问题
turningButton.getWebElement().click();
Thread.sleep(5000);
//翻页后再获取
System.out.println(t.getText(ce.getElement(FRIST_ID_XPATH)));
}
/**
* 测试列表元素调用{@link TextEvent#getText(pres.auxiliary.work.selenium.element.Element_Old)}方法
* @throws InterruptedException
*/
@Test
public void getTextTest_DataListElement() throws InterruptedException {
dle.add(ID_LIST_XPATH);
System.out.println("第一页:");
dle.getAllElement(ID_LIST_XPATH).forEach(element -> {
System.out.println(t.getText(element));
});
//测试元素过期问题
System.out.println("==========================================");
turningButton.getWebElement().click();
Thread.sleep(5000);
System.out.println("第二页:");
//翻页后再次获取
dle.getAllElement(ID_LIST_XPATH).forEach(element -> {
System.out.println(t.getText(element));
});
}
}

View File

@ -1,161 +0,0 @@
package pres.auxiliary.work.selenium.xml;
import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class ReadXmlTest {
XmlLocation r;
/**
* 初始化数据
*/
@BeforeClass
public void newReadXML() {
r = new XmlLocation(new File("src/test/java/pres/auxiliary/work/selenium/xml/测试用xml文件.xml"));
}
@AfterMethod
public void over(Method method) {
System.out.println("*****" + method.getName() + "运行完毕" + "*****");
}
/**
* 用于测试{@link XmlLocation#getBy(String, ByType)}方法获取普通元素
*/
@Test
public void getByTest_Element() {
System.out.println(r.getBy("XX控件7", ByType.XPATH));
}
/**
* 用于测试{@link XmlLocation#getBy(String, ByType)}方法获取窗体元素
*/
@Test
public void getByTest_Iframe() {
System.out.println(r.getBy("窗体1.1", ByType.XPATH));
}
/**
* 用于测试{@link XmlLocation#getBy(String, ByType)}方法获取模板元素
*/
@Test
public void getByTest_Templet() {
System.out.println(r.getBy("XX控件11", ByType.XPATH));
System.out.println(r.getBy("窗体1", ByType.CSS));
}
/**
* 用于测试{@link XmlLocation#getBy(String, ByType)}方法获取顶层元素
*/
@Test
public void getByTest_RootElement() {
System.out.println(r.getBy("XX控件1", ByType.XPATH));
}
/**
* 用于测试{@link XmlLocation#getValue(String, ByType)}方法获取普通元素
*/
@Test
public void getElementValueTest_Element() {
System.out.println(r.getValue("XX控件7", ByType.XPATH));
}
/**
* 用于测试{@link XmlLocation#getValue(String, ByType)}方法获取窗体元素
*/
@Test
public void getElementValueTest_Iframe() {
System.out.println(r.getValue("窗体1.1", ByType.XPATH));
}
/**
* 用于测试{@link XmlLocation#getValue(String, ByType)}方法获取模板元素
*/
@Test
public void getElementValueTest_Templet() {
System.out.println(r.getValue("XX控件11", ByType.XPATH));
System.out.println(r.getValue("窗体1", ByType.CSS));
}
/**
* 用于测试{@link XmlLocation#getValue(String, ByType)}方法获取顶层元素
*/
@Test
public void getElementValueTest_RootElement() {
System.out.println(r.getValue("XX控件1", ByType.XPATH));
}
/**
* 用于测试{@link XmlLocation#getIframeName(String, ByType)}方法获取普通元素
*/
@Test
public void getIframeNameTest_Element() {
System.out.println(r.getIframeName("XX控件7"));
}
/**
* 用于测试{@link XmlLocation#getIframeName(String, ByType)}方法获取窗体元素
*/
@Test
public void getIframeNameTest_Iframe() {
System.out.println(r.getIframeName("窗体1.1"));
}
/**
* 用于测试{@link XmlLocation#getIframeName(String, ByType)}方法获取模板元素
*/
@Test
public void getIframeNameTest_Templet() {
System.out.println(r.getIframeName("XX控件11"));
System.out.println(r.getIframeName("窗体1"));
}
/**
* 用于测试{@link XmlLocation#getIframeName(String)}方法获取顶层元素
*/
@Test
public void getIframeNameTest_RootElement() {
System.out.println(r.getIframeName("XX控件1"));
}
/**
* 用于测试{@link XmlLocation#getIframeName(String)}方法获取模板元素
*/
@Test
public void getIframeNameTest_NoPram() {
System.out.println(r.getIframeName("XX控件12"));
}
/**
* 用于测试{@link XmlLocation#getValue(String, ByType)}方法未查找到替换的属性
*/
@Test
public void getValueTest_NoPram() {
System.out.println(r.getValue("XX控件12", ByType.XPATH));
System.out.println(r.getValue("窗体3", ByType.XPATH));
}
/**
* 用于测试{@link XmlLocation#getValue(String, ByType)}方法外链关键词
*/
@Test
public void getValueTest_Link() {
ArrayList<String> link = new ArrayList<>();
link.add("测试1");
link.add("测试2");
link.add("测试3");
//XXX模板控件1[@X='${src}']/div[@name='${name}']
System.out.println(r.getValue("XX控件13", ByType.XPATH, link));
System.out.println(r.getValue("窗体3", ByType.XPATH, link));
//XXX模板控件1[@X='${src}']/div[@name='${name}']/div[@is='${str1}' and text()='${str1}']
System.out.println(r.getValue("XX控件14", ByType.XPATH, link));
//XXX模板控件1[@X='${src}']/div[@name='${name}']/div[@is='${str1}' and text()='${src}']/span[text()='${str2}']/span[id='${aaaa}']
System.out.println(r.getValue("XX控件15", ByType.XPATH, link));
}
}

View File

@ -1,89 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="">
<templet>
<xpath id='1'>//XXX模板控件1[@X='${name}']/div/div[@${att}='${id}']/input</xpath>
<css id='2'>http body ${tagName}</css>
<xpath id='3'>//XXX模板控件1[@X='${src}']/div[@name='${name}']</xpath>
<xpath id='4'>//XXX模板控件1[@X='${src}']/div[@name='${name}']/div[@is='${str1}' and text()='${str1}']</xpath>
<xpath id='5'>//XXX模板控件1[@X='${src}']/div[@name='${name}']/div[@is='${str1}' and text()='${src}']/span[text()='${str2}']/span[id='${aaaa}']</xpath>
</templet>
<element name='XX控件1'>
<xpath is_use='true'>//XX控件1[@X='XXXX']</xpath>
</element>
<iframe name='窗体1' >
<xpath is_use='true'>//窗体1[@X='XXXX']</xpath>
<css temp_id='2' tagName='iframe'/>
<element name='XX控件2'>
<xpath is_use='true'>//XX控件2[@X='XXXX']</xpath>
</element>
<element name='XX控件3'>
<xpath is_use='true'>//XXX控件3[@X='XXXX']</xpath>
</element>
<iframe name='窗体1.1' >
<xpath is_use='true'>//窗体1.1[@X='XXXX']</xpath>
<element name='XX控件4'>
<xpath is_use='true'>//XXX控件4[@X='XXXX']</xpath>
</element>
<element name='XX控件5'>
<xpath is_use='true'>//XXX控件5[@X='XXXX']</xpath>
</element>
<iframe name='窗体1.1.1' >
<xpath is_use='true'>//窗体1.1.1[@X='XXXX']</xpath>
<element name='XX控件6'>
<xpath is_use='true'>//XXX控件6[@X='XXXX']</xpath>
</element>
<element name='XX控件7'>
<xpath is_use='true'>//XXX控件7[@X='XXXX']</xpath>
</element>
</iframe>
</iframe>
<iframe name='窗体1.2' >
<xpath is_use='true'>//窗体1.2[@X='XXXX']</xpath>
<element name='XX控件8'>
<xpath is_use='true'>//XXX控件8[@X='XXXX']</xpath>
</element>
<element name='XX控件9'>
<xpath is_use='true'>//XXX控件9[@X='XXXX']</xpath>
</element>
</iframe>
</iframe>
<iframe name='窗体2' >
<xpath is_use='true'>//窗体2[@X='XXXX']</xpath>
<element name='XX控件10'>
<xpath is_use='true'>//XXX控件10[@X='XXXX']</xpath>
</element>
<element name='XX控件11'>
<xpath is_use='true' temp_id='1' id='Test' att='src'/>
<css is_use='true' temp_id='2' tagName='div'/>
<xpath is_use='true' temp_id='3' />
</element>
<element name='XX控件12'>
<xpath is_use='true' temp_id='3' />
</element>
</iframe>
<iframe name='窗体3' >
<xpath is_use='true'>//窗体3[@X='${ccc}']</xpath>
<element name='XX控件13'>
<xpath is_use='true' temp_id='3' />
</element>
<element name='XX控件14'>
<xpath is_use='true' temp_id='4' />
</element>
<element name='XX控件15'>
<xpath is_use='true' temp_id='5' />
</element>
</iframe>
</project>

View File

@ -0,0 +1 @@
/BasicTestCaseWriteTest.java

View File

@ -143,6 +143,7 @@ public class BasicTestCaseWriteTest {
*/
@Test
public void markFieldTest() {
@SuppressWarnings("rawtypes")
FieldMark cm = wtc.end().fieldComment("步骤", "步骤标记").fieldComment("预期", "预期标记");
cm.fieldComment("目的", "目的标记");
}
@ -152,6 +153,7 @@ public class BasicTestCaseWriteTest {
*/
@Test
public void fieldBackgroundTest() {
@SuppressWarnings("rawtypes")
FieldMark cm = wtc.end().changeFieldBackground("步骤", MarkColorsType.BLUE).changeFieldBackground("预期",
MarkColorsType.RED);
cm.changeFieldBackground("目的", MarkColorsType.GREEN);

View File

@ -1,58 +0,0 @@
package pres.readme.code;
import java.io.File;
import pres.auxiliary.work.testcase.templet.Case;
import pres.auxiliary.work.testcase.templet.LabelType;
public class MyCase extends Case {
public MyCase(File configXmlFile) {
super(configXmlFile);
}
public Case appBrowseListCase() {
//清空字段的内容
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addAppBrowseListCase";
//存储标题信息
addFieldText(LabelType.TITLE, getLabelText(caseName, LabelType.TITLE, "1"));
//添加步骤与预期
relevanceAddData(caseName, ALL, ALL);
//存储前置条件信息
addFieldText(LabelType.PRECONDITION, getAllLabelText(caseName, LabelType.PRECONDITION));
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
//存储优先级信息
addFieldText(LabelType.RANK, getLabelText(caseName, LabelType.RANK, "1"));
return this;
}
public Case webBrowseListCase() {
//清空字段的内容
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addWebBrowseListCase";
//存储标题信息
addFieldText(LabelType.TITLE, getLabelText(caseName, LabelType.TITLE, "1"));
//添加步骤与预期
relevanceAddData(caseName, ALL, ALL);
//存储前置条件信息
addFieldText(LabelType.PRECONDITION, getAllLabelText(caseName, LabelType.PRECONDITION));
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
//存储优先级信息
addFieldText(LabelType.RANK, getLabelText(caseName, LabelType.RANK, "1"));
return this;
}
}

View File

@ -1,50 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<cases>
<case name='myTest001'>
<steps>
<step id='1' value='myTest001_步骤1'/>
<step id='2' value='myTest001_步骤2'/>
</steps>
<excepts>
<except id='1' value='myTest001_预期1'/>
<except id='2' value='myTest001_预期2'/>
</excepts>
<titles>
<title id='1' value='myTest001_标题1*{条件}*' />
</titles>
<preconditions>
<precondition id='1' value='myTest001_前置1' />
<precondition id='2' value='myTest001_前置2' />
</preconditions>
<ranks>
<rank id='1' value='myTest001_优先级1' />
</ranks>
<keys>
<key id='1' value='myTest001_关键词1' />
</keys>
</case>
<case name='myTest002'>
<steps>
<step id='1' value='myTest002_步骤1_*{词语}*'/>
<step id='2' value='myTest002_步骤2'/>
<step id='3' value='myTest002_步骤3'/>
</steps>
<excepts>
<except id='1' value='myTest002_预期1'/>
</excepts>
<titles>
<title id='1' value='myTest002_标题1' />
</titles>
<preconditions>
<precondition id='1' value='myTest002_前置1' />
<precondition id='2' value='myTest002_前置2' />
</preconditions>
<ranks>
<rank id='1' value='myTest002_优先级1' />
</ranks>
<keys>
<key id='1' value='myTest002_关键词1' />
</keys>
</case>
</cases>

View File

@ -1,94 +0,0 @@
package pres.readme.code;
import java.io.File;
import java.io.IOException;
import org.dom4j.DocumentException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import pres.auxiliary.tool.file.excel.CreateExcelFile;
import pres.auxiliary.work.testcase.file.BasicTestCaseWrite;
import pres.auxiliary.work.testcase.templet.InformationCase;
import pres.auxiliary.work.testcase.templet.LabelType;
public class TestWriteCase {
/**
* 用例编写类
*/
BasicTestCaseWrite wtc;
/**
* 添加信息用例模板类
*/
InformationCase ic;
/**
* 配置文件类对象
*/
File conFile = new File(
"ConfigurationFiles/CaseConfigurationFile/FileTemplet/JiraCaseFileTemplet/jira测试用例导入模板.xml");
/**
* 模板文件类对象
*/
File tempFile = new File("Result/测试用例.xlsx");
/**
* 添加信息类测试用例模板文件
*/
File caseTempFile = new File("ConfigurationFiles/CaseConfigurationFile/CaseTemplet/AddInformation.xml");
@BeforeClass
public void createTemplet() throws DocumentException, IOException {
//创建测试用例模板文件
CreateExcelFile temp = new CreateExcelFile(conFile, tempFile);
temp.setCoverFile(true);
temp.create();
//构造用例编写类对象
wtc = new BasicTestCaseWrite(conFile, tempFile);
//添加常量词语
wtc.setFieldValue("模块", "/测试项目/账号管理/创建账号");
wtc.setFieldValue("目的", "验证创建账号界面各个控件输入是否有效");
wtc.setFieldValue("状态", "1");
wtc.setFieldValue("设计者", "test");
wtc.setFieldValue("关联需求", "TEST-1");
//添加与测试用例模板的字段关联
wtc.relevanceCase("步骤", LabelType.STEP.getName());
wtc.relevanceCase("预期", LabelType.EXCEPT.getName());
wtc.relevanceCase("前置条件", LabelType.PRECONDITION.getName());
wtc.relevanceCase("优先级", LabelType.RANK.getName());
wtc.relevanceCase("标题", LabelType.TITLE.getName());
//构造测试用例模板类对象
ic = new InformationCase(caseTempFile);
//添加需要替换的词语
ic.setReplaceWord(InformationCase.ADD_INFORMATION, "账号");
ic.setReplaceWord(InformationCase.BUTTON_NAME, "保存");
}
@AfterClass
public void openFolder() throws IOException {
java.awt.Desktop.getDesktop().open(wtc.getCaseXml());
//将测试用例内容写入到文件中
wtc.writeFile();
}
@Test
public void addCase() {
wtc.addCase(ic.addBasicTextboxCase("姓名", false, true, false)).end();
wtc.addCase(ic.addIdCardCase("身份证", true, false, false)).end();
wtc.setFieldValue("模块", "/测试项目/账号管理/创建账号2");
wtc.addCase(ic.addIdCardCase("护照号", true, false, false)).end();
}
@Test
public void myCaseTest() {
MyCase mc = new MyCase(new File("src/test/java/pres/readme/code/MyCase.xml"));
wtc.addCase(mc.myCase1()).end();
wtc.addCase(mc.myCase2("测试")).end();
wtc.addCase(mc.myCase3()).end();
}
}

View File

@ -1,172 +0,0 @@
package test.javase;
import java.util.ArrayList;
import java.util.Scanner;
/**
* <p><b>文件名</b>BlackHoleNumber.java</p>
* <p><b>用途</b>求取黑洞数</p>
* <p><b>编码时间</b>2018年12月24日 上午8:11:29</p>
* <p><b>问题描述</b>编程求三位数中的黑洞数<br>
* 黑洞数又称陷阱数任何一个数字不全相同的整数经有限次重排求差操作
* 总会得到某一个或一些数这些数即为黑洞数重排求差操作是将组成一个数
* 的各位数字重排得到的最大数减去最小数例如207重排求差操作序列是720-027=693
* 963-369=594954-459=495再做下去就不变了再用208算一次
* 也停止到495所以495是三位黑洞数</p>
*
* <p><b>问题分析</b>根据黑洞数定义对于任一个数字不全相同的整数
* 最后结果总会掉入到一个黑洞圈或黑洞数里最后结果一旦为黑洞数无论再重复
* 进行多少次的重排求差操作则结果都是一样的可把结果相等作为判断黑洞
* 的依据</p>
*
* <p><b>过程如下</b>
* <ol>
* <li>将任一个三位数进行拆分</li>
* <li>拆分后的数据重新组合将可以组合的最大值减去最小值差赋给变量j</li>
* <li>将当前差值暂存到另一变量h中h=j</li>
* <li>对变量j执行拆分重组求差操作差值仍然存储到变量j中</li>
* <li>判断当前差值j是否与前一次的差相等若相等将差值输出并结束循环否则重复步骤 34和 5</li>
* </ol>
* </p>
* @author Linux公社
*/
public class BlackHoleNumber {
//存储每次重排后得到的运算结果
private static ArrayList<Integer> numList = new ArrayList<>();
@SuppressWarnings("resource")
public static void main(String[] args) {
int i;
int max, min, j = 0;
//控制循环次数
int k = 0;
System.out.println("请输入一个数字:");
i = new Scanner(System.in).nextInt();
//获取最大最小的数字
max = maxNumber(i);
min = minNumber(i);
//j=max-min;
//循环进行运算
while(true) {
//计算两数之差
j=max-min;
//通过showBlackHole()方法判断运算结果是否掉入黑洞若在黑洞中则结束循环
if(showBlackHole(j))
{
break;
}
System.out.println("" + ++k + "次运算:" + max + "-" + min + " = " + j);
//获取最大最小的数字
max = maxNumber(j);
min = minNumber(j);
}
}
/**
* 求取数字重排后的最大的数字
* @param num 需要重排的数字
* @return 重排后得到的最大数字
*/
private static int maxNumber(int num) {
//将字符串逐一切开
String[] nums = String.valueOf(num).split("");
//将切分到的字符串转成数字
int[] numbers = new int[nums.length];
for ( int i = 0; i < nums.length; i++ ) {
numbers[i] = Integer.valueOf(nums[i]);
}
//冒泡排序按照从大到小的顺序进行排序
for ( int i = 0; i < numbers.length - 1; i++ ) {
for ( int j = 0; j < numbers.length - 1 - i; j++ ) {
if ( numbers[j] < numbers[j + 1] ) {
int temp = numbers[j];
numbers[j] = numbers[j + 1];
numbers[j + 1] = temp;
}
}
}
//将重排得到的数字组合成字符串
String numberText = "";
for ( int number : numbers ) {
numberText += number;
}
//将字符串转换为数字
return Integer.valueOf(numberText);
}
/**
* 求取数字重排后的最大的数字
* @param num 需要重排的数字
* @return 重排后得到的最大数字
*/
private static int minNumber(int num) {
//将字符串逐一切开
String[] nums = String.valueOf(num).split("");
//将切分到的字符串转成数字
int[] numbers = new int[nums.length];
for ( int i = 0; i < nums.length; i++ ) {
numbers[i] = Integer.valueOf(nums[i]);
}
//冒泡排序按照从大到小的顺序进行排序
for ( int i = 0; i < numbers.length - 1; i++ ) {
for ( int j = 0; j < numbers.length - 1 - i; j++ ) {
if ( numbers[j] > numbers[j + 1] ) {
int temp = numbers[j];
numbers[j] = numbers[j + 1];
numbers[j + 1] = temp;
}
}
}
//将重排得到的数字组合成字符串
String numberText = "";
for ( int number : numbers ) {
numberText += number;
}
//将字符串转换为数字
return Integer.valueOf(numberText);
}
/**
* 用于判断并显示黑洞数
* @param num 运算结果
* @return 是否为黑洞数
*/
private static boolean showBlackHole(int num) {
//用于循环后判断该数字是否为黑洞数
boolean blackHole = false;
//循环判断数字是否已在列表中若存在则说明计算结果已进入循环可进行输出
int i = 0;
for (; i < numList.size(); i++ ) {
if ( numList.get(i) == num ) {
blackHole = true;
break;
}
}
//若循环结束后其数字是一个黑洞数则输出黑洞数不是则存储运算结果
if ( blackHole ) {
System.out.print("黑洞数为:");
//由于上次循环发现重复后则直接结束了循环故此处可以直接衔接上循环来输出结果
for (; i < numList.size(); i++ ) {
System.out.print(numList.get(i));
if ( i < numList.size() - 1 ) {
System.out.print("");
}
}
} else {
numList.add(num);
}
return blackHole;
}
}

View File

@ -1 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="">
<element name='Html'>
<xpath is_use='true'>/html/body/div[4]/div[1]/div[2]/div[1]/a[1]/h4[1]</xpath>
<css is_use='true'>html body div.container.main div.row
div.col.middle-column-home div.codelist.codelist-desktop.cate1
a.item-top.item-1 h4</css>
</element>
</project>

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<bug>
<projected name="泰滴项目">
<version version="V0.1" time="2018-">
<one number="1" />
<two number="21" />
<three number="34" />
<four number="10" />
</version>
<version version="V0.2">
<one number="0" />
<two number="10" />
<three number="23" />
<four number="3" />
</version>
</projected>
<projected name="那坡扶贫项目">
<version version="V0.1">
<one number="0" />
<two number="13" />
<three number="25" />
<four number="7" />
</version>
</projected>
</bug>

View File

@ -1,25 +0,0 @@
package test.javase;
import pres.auxiliary.tool.string.RandomString;
import pres.auxiliary.tool.string.StringMode;
public class RandomPhone {
public static void main(String[] args) {
String s = "133,153,180,181,189,177,1700,199";
RandomString rs = new RandomString(StringMode.NUM);
for (String ss : s.split("\\,")) {
if (ss.length() == 3) {
System.out.println(ss + rs.toString(8));
System.out.println(ss + rs.toString(7));
System.out.println(ss + rs.toString(9));
System.out.println(ss + "@" + rs.toString(7));
} else {
System.out.println(ss + rs.toString(7));
System.out.println(ss + rs.toString(6));
System.out.println(ss + rs.toString(8));
System.out.println(ss + "@" + rs.toString(6));
}
}
}
}

View File

@ -1,65 +0,0 @@
package test.javase;
import java.util.ArrayList;
import pres.auxiliary.tool.string.RandomString;
/**
* FileName: SweepPlan.java
*
* 用于进行值日安排
*
* @author 彭宇琦
* @Deta 2019年1月9日 上午9:23:23
* @version ver1.0
*/
public class SweepPlan {
public static void main(String[] args) {
//6个值日地点1表示女厕2表示男厕3表示老总办公室倒垃圾4表示前台倒垃圾5表示大厅6表示大厅
RandomString rs = new RandomString("123456");
rs.setRepeat(false);
String s = "";
ArrayList<String> l = new ArrayList<>();
l.add("彭宇琦");l.add("韦 顺");l.add("蓝石玉");l.add("梁俊宏");l.add("梁叶辰");l.add("梁文玉");
for ( int j = 1; j < 4; j++ ) {
System.out.println("-----------第" + j + "次结果-----------");
//分配任务
while( true ) {
s = rs.toString(6);
//如果女厕未安排女生则重新安排
if( s.charAt(4) != '1' && s.charAt(5) != '1' ) {
continue;
}
//如果男厕安排到女生则重新安排
if ( s.charAt(4) == '2' || s.charAt(5) == '2' ) {
continue;
}
break;
}
for ( int i = 0; i < l.size(); i++ ) {
System.out.println(l.get(i) + ":" + show(s.charAt(i)));
}
}
}
//用于将数字翻译成值日位置
public static String show(char c) {
switch(c) {
case '1' :
return "女厕";
case '2' :
return "男厕";
case '3' :
return "老总办公室、倒垃圾";
case '4' :
return "前台、倒垃圾";
case '5' :
return "大厅";
case '6' :
return "大厅";
default:
return "";
}
}
}

View File

@ -1,14 +0,0 @@
package test.javase;
public class Test123 {
public static void main(String[] args) throws Exception {
String s = "Fgfdsdfg\\sfdggwe\\grew.gsfd.sdf.txt";
String ss = "Fgfdsdfg\\sfdggwe\\grew";
System.out.println(s.split("\\.").length);
System.out.println(ss.split("\\.").length);
System.out.println("The End");
//System.out.pri ntln(UUID.randomUUID().toString());
}
}

View File

@ -1,100 +0,0 @@
package test.javase;
import java.io.IOException;
import java.lang.reflect.Parameter;
public class TestAddCase {
public static void main(String[] args) throws IOException {
/*
ZentaoTemplet.setFileName("商品车车辆物流管控平台项目");
ZentaoTemplet.create();
PresetCase p = new PresetCase();
p.setModule("/商品车车辆物流管控平台/登录");
p.getUsername().rightLoginCase();
p.getUsername().errorLoginCase();
p.setModule("/商品车车辆物流管控平台/百度地图");
p.getMap().mapPointCase("车辆");
p.getMap().rangeFindingCase();
p.getMap().carLocusPlaybackCase();
p.getBrowseList().addWebBrowseListCase("实时信息");
p.getBrowseList().addWebBrowseListCase("报警");
p.setModule("/商品车车辆物流管控平台/系统设置/修改密码");
p.getUsername().alterPasswordCase();
p.setModule("/商品车车辆物流管控平台/系统设置/人工确认报警");
p.getBrowseList().addWebBrowseListCase("报警信息");
p.getBrowseList().addSelectSearchCase("车组", "报警信息");
p.getBrowseList().addSelectSearchCase("车辆", "报警信息");
p.getBrowseList().addSelectSearchCase("处理状态", "报警信息");
p.getBrowseList().addDateSearchCase("报警时间", true, "报警信息");
p.getBrowseList().addExportListCase("报警信息", true);
p.setModule("/商品车车辆物流管控平台/外接设备管理/IC卡查询");
p.getBrowseList().addWebBrowseListCase("IC卡");
p.getBrowseList().addInputSearchCase("卡号", "IC卡");
p.getBrowseList().addDateSearchCase("报警时间", true, "IC卡");
p.setModule("/商品车车辆物流管控平台/外接设备管理/IC卡管理");
p.getAddInformation().setButtonName("添加");
p.getAddInformation().setInformationName("IC卡");
p.getAddInformation().setFailExpectation("IC卡添加失败并给出相应的提示");
p.getAddInformation().setSuccessExpectation("IC卡添加成功并显示在下方的IC卡列表中");
p.getAddInformation().addWholeInformationCase();
p.getAddInformation().addUnWholeInformationCase();
p.getAddInformation().addTextboxCase("卡号", true, false, new char[]{InputType.NUM}, null, null);
p.getAddInformation().addTextboxCase("密码", true, true, new char[]{InputType.NUM, InputType.EN}, null, null);
p.getAddInformation().addTextboxCase("确认密码", true, true, new char[]{InputType.NUM, InputType.EN}, null, null);
p.getAddInformation().addSelectboxCase("IC卡类型", true);
p.getAddInformation().addTextboxCase("持卡人", true, true, null, null, null);
p.getAddInformation().addSelectboxCase("模式", true);
p.getOperateInformation().addEditCase("IC卡");
p.getBrowseList().addWebBrowseListCase("IC卡");
p.setModule("/商品车车辆物流管控平台/外接设备管理/里程统计信息");
p.getBrowseList().addWebBrowseListCase("里程信息");
p.getBrowseList().addInputSearchCase("卡号", "里程信息");
p.getBrowseList().addDateSearchCase("统计时间", true, "里程信息");
p.getBrowseList().addExportListCase("里程信息", true);
p.setModule("/商品车车辆物流管控平台/报表功能/车辆状态查询");
p.getBrowseList().addWebBrowseListCase("车辆状态");
p.getBrowseList().addSelectSearchCase("车组", "车辆状态");
p.getBrowseList().addSelectSearchCase("车辆", "车辆状态");
p.getBrowseList().addDateSearchCase("不在线时间", false, "车辆状态");
*/
A a = new A();
a.show();
System.out.println("The End");
}
public TestAddCase() {
System.out.println(this.getClass().getSimpleName());
}
}
class A extends B {
public void show() {
method(Thread.currentThread().getStackTrace()[Thread.currentThread().getStackTrace().length - 2].getMethodName());
}
}
class B {
public void method(String s) {
try {
Parameter[] pars = this.getClass().getMethod(Thread.currentThread().
getStackTrace()[Thread.currentThread().getStackTrace().length - 3].getMethodName(), String.class).getParameters();
for ( Parameter par : pars ) {
System.out.println(par.getName());
}
} catch (NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
System.out.println(s);
}
}

View File

@ -1,50 +0,0 @@
package test.javase;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFHyperlink;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class TestAddCellLink {
public static void main(String[] args) throws Exception {
// 构造ecxel对象
XSSFWorkbook xw = null;
File f = new File("C:\\AutoTest\\Record\\AutoTestRecord - 副本.xlsx");
try {
FileInputStream fip = new FileInputStream(f);
xw = new XSSFWorkbook(fip);
fip.close();
} catch (IOException e) {
e.printStackTrace();
}
XSSFCell xc = xw.getSheet("运行记录").getRow(2).getCell(3);
// 使用creationHelpper来创建XSSFHyperlink对象
CreationHelper createHelper = xw.getCreationHelper();
XSSFHyperlink link = (XSSFHyperlink) createHelper.createHyperlink(HyperlinkType.DOCUMENT);
link.setAddress("#错误记录!A2");
xc.setHyperlink(link);
// 将内容写入文件
try {
FileOutputStream fop = new FileOutputStream(new File("C:\\AutoTest\\Record\\AutoTestRecord - 副本.xlsx"));
xw.write(fop);
fop.close();
xw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
java.awt.Desktop.getDesktop().open(new File("C:\\AutoTest\\Record\\AutoTestRecord - 副本.xlsx"));
}
}

View File

@ -1,30 +0,0 @@
package test.javase;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;
import pres.auxiliary.tool.string.RandomString;
import pres.auxiliary.tool.string.StringMode;
public class TestArrayList {
public static void main(String[] args) {
ArrayList<String> al = new ArrayList<String>();
int count = 10000000;
System.out.println("开始添加" + count + "个随机内容");
Date start = new Date();
for (int i = 0; i < count; i++) {
al.add(new RandomString(StringMode.CH).toString(10, 30));
}
System.out.println("添加完毕,耗时:" + (new Date().getTime() - start.getTime()));
System.out.println("随机抽取10个内容");
start = new Date();
for (int i = 0; i < 10; i++) {
System.out.println("" + (i + 1) + "个内容:" + al.get(new Random().nextInt(10000)));
}
System.out.println("抽取完毕,耗时:" + (new Date().getTime() - start.getTime()));
}
}

View File

@ -1,39 +0,0 @@
package test.javase;
import pres.auxiliary.report.ui.TestReportUI;
public class TestAutoWriteReport {
public static void main(String[] args) {
//TestReport tr = new TestReport();
//System.out.println(tr.AutoWriteReport(true, true));
//TestReportMainFrame.Main();
TestReportUI.open();
//tr.compressReportFile(new File("C:\\AutoTest\\Report\\隆安OA扶贫项目Ver0.4版本测试报告"));
//System.out.println("The End");
// System.out.println(new File("E:\\Work\\1.项目测试\\隆安OA项目\\扶贫后台管理系统\\V0.2\\隆安OA扶贫项目Ver0.2版本测试报告").getParent());
// System.out.println(new File("E:\\Work\\1.项目测试\\隆安OA项目\\扶贫后台管理系统\\V0.2\\隆安OA扶贫项目Ver0.2版本测试报告").getName());
/*
//网络不好时使用
tr.createReport(bugListFile, testDay, person, range);
tr.compressReportFile(new File("C:\\AutoTest\\Report\\隆安OA扶贫项目Ver0.4版本测试报告"));
tr.sandMail(tr.getMailContent(), "隆安OA扶贫项目", "隆安OA扶贫项目Ver0.4版本测试报告", new File("C:\\AutoTest\\Report\\隆安OA扶贫项目Ver0.4版本测试报告.zip"));
*/
/*
String[][] ts = tr.getMailToAndCc("那坡县");
for (String[] s : ts) {
for (String ss : s) {
System.out.println(ss);
}
}
*/
//System.out.println(s());
//System.out.println(new Random().nextDouble());
/*
UUID uuid = UUID.randomUUID();
System.out.println(uuid);
*/
}
}

View File

@ -1,22 +0,0 @@
package test.javase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TestBefore {
@Test
public static void show() {
System.out.println("haha");
}
@Before
public static void before() {
System.out.println("xixi");
}
@After
public static void after() {
System.out.println("hehe");
}
}

View File

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<templet name="AddInformation">
<case name="addTextboxCase">
<前置依赖配置>新增不同&name&&informationName</前置依赖配置>
<title>新增不同&name&&informationName</title>
<st_and_ex mark="isMsut">
<step>不填写或只输入空格,点击“&ButtonName&”按钮</step>
</st_and_ex>
<st_and_ex mark="isRepeat">
<step>不填写或只输入空格,点击“&ButtonName&”按钮</step>
</st_and_ex>
<st_and_ex>
<step>填写特殊字符或HTML代码点击“&ButtonName&”按钮</step>
</st_and_ex>
<st_and_ex mark="inputConfine">
<step>输入非&CharType&字符,点击“&ButtonName&”按钮</step>
</st_and_ex>
</case>
<function name="inputConfineStep">
<前置依赖配置>新增不同&name&&informationName</前置依赖配置>
<title>新增不同&name&&informationName</title>
<st_and_ex mark="isMsut">
<step>不填写或只输入空格,点击“&ButtonName&”按钮</step>
</st_and_ex>
<st_and_ex mark="isRepeat">
<step>不填写或只输入空格,点击“&ButtonName&”按钮</step>
</st_and_ex>
<st_and_ex>
<step>填写特殊字符或HTML代码点击“&ButtonName&”按钮</step>
</st_and_ex>
<st_and_ex mark="inputConfine">
<step>输入非&CharType&字符,点击“&ButtonName&”按钮</step>
</st_and_ex>
</case>
</templet>

View File

@ -1,91 +0,0 @@
package test.javase;
import java.io.IOException;
import pres.auxiliary.tool.string.RandomString;
import pres.auxiliary.tool.string.StringMode;
import pres.auxiliary.work.old.testcase.templet.ZentaoTemplet;
public class TestCase2 {
public static void main(String[] args) throws IOException {
String s = "测试" + new RandomString(StringMode.ALL).toString();
ZentaoTemplet.setSavePath("E:\\");
ZentaoTemplet.setFileName(s);
ZentaoTemplet.create();
/*
AddInformation a = new AddInformation();
a.setModule("测试模块");
a.setPrecondition("已在新增信息界面", "所有信息均正确填写");
a.setSuccessExpectation("新增成功");
a.setFailExpectation("新增失败");
a.setButtonName("提交");
a.setInformationName("活动");
a.addWholeInformationCase().setTab("哈哈").setRowColorTab(Tab.BLUE);
System.out.println("Step:");
System.out.println(a.getStep());
System.out.println("Expectation:");
System.out.println(a.getExpectation());
System.out.println();
a.addUnWholeInformationCase();
System.out.println("Step:");
System.out.println(a.getStep());
System.out.println("Expectation:");
System.out.println(a.getExpectation());
System.out.println();
*/
/*
AddInformation a = new AddInformation();
BrowseList b = new BrowseList();
MyCase c = new MyCase();
a.setModule("测试模块");
a.setPrecondition("已在新增信息界面", "所有信息均正确填写");
a.setSuccessExpectation("新增成功");
a.setFailExpectation("新增失败");
a.setButtonName("提交");
a.setInformationName("活动");
a.addWholeInformationCase().setTab("哈哈").setRowColorTab(Tab.BLUE);
a.addUnWholeInformationCase();
a.addTextboxCase("名称", true, false, null, new int[]{a.NUM_NAN, 10}, null);
//实验自定义
c.addTitle("新增不同电话号码的人物").
addStep("我去", "我不去").
addExpectation("输入失败").
addKeyword("新增", "电话号码").
addRank(1).
addPrecondition("已在新增页面", "所有信息均正确填写").
end().
setRowColorTab(Tab.GREEN);
a.addTextboxCase("活动代号", true, false, new char[]{InputType.NUM, InputType.EN}, new int[]{5, a.NUM_NAN}, null);
a.addSelectboxCase("活动类型", true);
a.addTextboxCase("参与人数", false, true, new char[]{InputType.NUM}, null, new int[]{10, 50});
a.addTextboxCase("实到人数", false, true, new char[]{a.INPUT.NUM}, null, new int[]{a.NUM_NAN, 50});
a.addTextboxCase("活动地点", false, true, null, new int[]{10, 30}, null);
a.addStartDateCase("活动开始时间", true, true, "true");
a.addEndDateCase("活动结束时间", true, true, "false");
a.addDateCase("出发日期", false, true);
a.addCheckboxCase("出行工具", false);
a.addRadioButtonCase("主持人性别", false);
a.addPhoneCase("主持人电话", false, true, PhoneType.MOBLE);
a.addIDCardCase("主持人身份证号", false, true);
a.addUploadImageCase("活动剪影", true, false, false, true, false, new char[]{a.FILE.JPG, a.FILE.BMP, a.FILE.PNG}, new int[]{3, a.NUM_NAN});
a.addUploadFileCase("活动事项及通知", false, false, false, new char[]{a.FILE.DOC, a.FILE.DOCX, a.FILE.XLS, a.FILE.XLSX, a.FILE.TXT}, null);
b.addAppBrowseListCase("活动列表");
b.addWebBrowseListCase("活动列表");
// b.addSearchCase("名称", "活动地点", "主持人姓名", "活动代号");
*/
System.out.println("The end");
}
}

View File

@ -1,56 +0,0 @@
package test.javase;
import java.io.IOException;
/**
* FileName: TestCase3.java
*
* 用于测试2018年6月13日最近编写的测试用例模版的正确性
*
* @author 彭宇琦
* @Deta 2018年6月13日 上午10:09:27
* @version ver1.0
*/
public class TestCase3 {
public static void main(String[] args) throws IOException {
/*
ZentaoTemplet.setFileName(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
ZentaoTemplet.create();
PresetCase p = new PresetCase();
p.setModule("测试模块");
p.getMap().carLocusPlaybackCase();
p.getMap().mapPointCase("车辆");
p.getMap().mapSearchInformationCase("车牌号", "车辆");
p.getMap().rangeFindingCase();
p.getMap().showLocusCase("点轨迹", "线轨迹", "全部轨迹");
p.getVideo().playVideoCase(true);
p.getVideo().videoAdvanceCase(true, true);
p.getVideo().videoScreenshotCase();
p.getVideo().videoProgressBarCase();
p.getVideo().videoSpeedCase(true);
p.getVideo().fullScreenPlayCase();
p.getVideo().setVideoType("录像");
p.getVideo().fullScreenPlayCase();
p.getVideo().videoSpeedCase(true);
p.getUsername().alterPasswordCase();
p.getUsername().usernameRegisterCase(true);
p.getUsername().passwordRegisterOrForgetCase("注册");
p.getUsername().codeRegisterOrForgetCase("注册", true);
p.getUsername().usernameForgetCase();
p.getUsername().passwordRegisterOrForgetCase("忘记密码");
p.getUsername().codeRegisterOrForgetCase("忘记密码", true);
Username u = new Username(new File("E:\\泰滴后台管理系统测试用例.xlsx"));
u.setModule("呵呵");
u.codeRegisterOrForgetCase("注册", true);
java.awt.Desktop.getDesktop().open(new File("E:\\"));
//java.awt.Desktop.getDesktop().open(new File(ZentaoTemplet.getSavePath()));
*/
String s = "hahahahhah";
System.out.println(s.substring(s.indexOf("5")));
}
}

View File

@ -1,12 +0,0 @@
package test.javase;
import java.io.File;
public class TestCreateXml {
public static void main(String[] args) throws XmlFileNameIsNullException {
CreateXml.setMode(CreateXml.XPATH, CreateXml.CSS);
CreateXml.create(new File("ConfigurationFiles/ReportConfigurationFile/txt").listFiles());
System.out.println("The End");
}
}

View File

@ -1,20 +0,0 @@
package test.javase;
import java.io.File;
import java.io.FileReader;
import com.opencsv.CSVReader;
public class TestCsv {
public static void main(String[] args) throws Exception {
CSVReader csv = new CSVReader(new FileReader(new File("src/test/java/test/javase/resource/test.csv")));
String[] s;
while((s = csv.readNext()) != null) {
for (String ss : s) {
System.out.println(ss);
}
}
csv.close();
}
}

View File

@ -1,58 +0,0 @@
package test.javase;
import java.io.IOException;
public class TestDate {
public static void main(String[] args) throws IOException {
/*
Date d = new Date();
System.out.println(new SimpleDateFormat("yyyy.MM.dd").format(d));
d.setDate(d.getDate() + 50);
System.out.println(new SimpleDateFormat("yyyy.MM.dd").format(d));
System.out.println(new File("C:\\tes1t").exists());
// 用于读取模版文件
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File("Templet\\TestReportTemplet.docx")));
// 用于创建用户定义的文件夹
File f = new File("C:\\AutoTest\\TestReport");
// 判断文件夹是否创建若已创建则不再创建
if (!f.exists()) {
f.mkdirs();
}
// 用于写入到用户定义的文件夹中
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f + "\\copy.docx"));
// 用于作为缓冲的byte数组
byte[] b = new byte[1024];
// 读取文本的一段
int i = bis.read(b);
// 循环直至文本被完全写入
while (i != -1) {
bos.write(b);
bos.flush();
i = bis.read(b);
}
// 关闭流
bis.close();
bos.close();
*/
String s = "1.2.3-4-5-6-7-8-9";
String[] ss;
ss = s.split("\\.");
for (String sss : ss) {
System.out.println(sss);
}
System.out.println();
ss = ss[2].split("-");
for (String sss : ss) {
System.out.println(sss);
}
System.out.println(Integer.MAX_VALUE);
System.out.println("The End");
}
}

View File

@ -1,22 +0,0 @@
package test.javase;
import java.io.File;
import java.io.IOException;
import pres.auxiliary.work.old.testcase.templet.ZentaoTemplet;
/**
* FileName: TestDisposeCaseFile.java
*
* 用于测试处理测试用例文件方法
*
* @author 彭宇琦
* @Deta 2018年6月22日 下午5:44:01
* @version ver1.0
*/
public class TestDisposeCaseFile {
public static void main(String[] args) throws IOException {
ZentaoTemplet.disposeCaseFile(new File("E:\\Case.xlsx"));
System.out.println("The End");
}
}

View File

@ -1,10 +0,0 @@
package test.javase;
import pres.auxiliary.work.old.testcase.writecase.InputType;
public class TestEn {
public static void main(String[] args) {
InputType INPUT = null;
System.out.println(InputType.CH);
}
}

View File

@ -1,13 +0,0 @@
package test.javase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class TestGetText {
public static void main(String[] args) {
FirefoxBrower fb = new FirefoxBrower("http://www.hao123.com");
WebDriver d = fb.getDriver();
System.out.println(d.findElement(By.xpath("//*[@id=\"menus\"]/li[4]/a")).getText());
}
}

View File

@ -1,69 +0,0 @@
package test.javase;
import java.util.Arrays;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
public class TestJSONObject {
public static void main(String[] args) {
JSONObject methodJson1 = new JSONObject();
methodJson1.put("name", "测试方法1");
methodJson1.put("bug", 5);
methodJson1.put("step", 7);
methodJson1.put("isBugMethod", false);
JSONObject methodJson2 = new JSONObject();
methodJson2.put("name", "测试方法2");
methodJson2.put("bug", 1);
methodJson2.put("step", 3);
methodJson2.put("isBugMethod", true);
JSONObject methodJson3 = new JSONObject();
methodJson3.put("name", "测试方法3");
methodJson3.put("bug", 4);
methodJson3.put("step", 10);
methodJson3.put("isBugMethod", false);
JSONObject testClassJson1 = new JSONObject();
testClassJson1.put("name", "测试类1");
testClassJson1.put("method", Arrays.asList(methodJson1.toString(), methodJson2.toString()));
JSONObject testClassJson2 = new JSONObject();
testClassJson2.put("name", "测试类2");
testClassJson2.put("method", Arrays.asList(methodJson3.toString()));
JSONObject moduleJson = new JSONObject();
moduleJson.put("name", "测试模块");
moduleJson.put("testClass", Arrays.asList(testClassJson1.toString(), testClassJson2.toString()));
//System.out.println(moduleJson);
System.out.println("模块信息输出:");
JSONObject outputModuleJson = JSON.parseObject(moduleJson.toString());
System.out.println(outputModuleJson.get("name"));
outputModuleJson.getJSONArray("testClass").forEach(System.out :: println);
System.out.println("-".repeat(20));
System.out.println("测试类输出:");
outputModuleJson.getJSONArray("testClass").forEach(testClassJson -> {
JSONObject outputTestClassJson = JSON.parseObject(testClassJson.toString());
System.out.println(outputTestClassJson.get("name"));
outputTestClassJson.getJSONArray("method").forEach(System.out :: println);
});
System.out.println("-".repeat(20));
System.out.println("测试方法输出:");
outputModuleJson.getJSONArray("testClass").forEach(testClassJson -> {
JSONObject outputTestClassJson = JSON.parseObject(testClassJson.toString());
outputTestClassJson.getJSONArray("method").forEach(methodJson -> {
JSONObject outputMethodJson = JSON.parseObject(methodJson.toString());
System.out.println(outputMethodJson.get("name"));
System.out.println(outputMethodJson.get("step"));
System.out.println(outputMethodJson.get("bug"));
System.out.println(outputMethodJson.get("isBugMethod"));
});
});
System.out.println("-".repeat(20));
}
}

View File

@ -1,18 +0,0 @@
package test.javase;
import java.util.ArrayList;
import java.util.Collection;
public class TestLambda {
public static void main(String[] args) {
//lambda遍历Collection
Collection<String> l = new ArrayList<String>();
l.add("haha");
l.add("xixi");
l.add("gege");
l.forEach(c -> {
c += "1";
System.out.println(c);
});
}
}

View File

@ -1,100 +0,0 @@
package test.javase;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.testng.annotations.Test;
public class TestList {
@Test
public void test() {
//TODO
SwitchFrame sf = new SwitchFrame();
}
class SwitchFrame {
private ArrayList<String> parentIframeList = new ArrayList<String>();
ArrayList<String> iframeNameList = new ArrayList<String>();
public SwitchFrame() {
parentIframeList.add("f1");
parentIframeList.add("f2");
parentIframeList.add("f3");
}
/**
* 该方法用于将窗体切回顶层当本身是在最顶层时则该方法将使用无效
*/
public void switchRootFrame() {
//清空iframeNameList中的内容
iframeNameList.clear();
}
/**
* 该方法用于将窗体切换到上一层父层若当前层只有一层则调用方法后切回顶层
* 若当前层为最顶层时则该方法将使用无效
*/
public void switchParentFrame() {
//若iframeNameList大于1层则向上切换窗体
if (iframeNameList.size() > 1) {
iframeNameList.remove(iframeNameList.size() - 1);
} else if (iframeNameList.size() == 1) {
//若iframeNameList等于1层则调用切换至顶层的方法
switchRootFrame();
} else {
//若iframeNameList小于1层则不做操作
return;
}
}
/**
* 通过传入在xml文件中的控件名称到类中指向的xml文件中查找控件
* 名称对应的定位方式或直接传入xpath与css定位方式
* 根据定位方式对相应的窗体进行定位当传入的窗体为当前窗体的前层父层窗体时
* 通过该方法将调用切换父层的方法将窗体切换到父层上例如<br>
* 当前存在f1, f2, f3, f4四层窗体则调用方法<br>
* switchFrame("f2")<br>
* 此时窗体将回到f2层无需再从顶层开始向下切换<br>
* 注意窗体的切换按照从前向后的顺序进行切换切换顺序不能相反
*
* @param names 窗体的名称或xpath与css定位方式
*/
public void switchFrame(String...names) {
switchFrame(Arrays.asList(names));
}
/**
* 通过传入在xml文件中的控件名称到类中指向的xml文件中查找控件
* 名称对应的定位方式或直接传入xpath与css定位方式
* 根据定位方式对相应的窗体进行定位当传入的窗体为当前窗体的前层父层窗体时
* 通过该方法将调用切换父层的方法将窗体切换到父层上例如<br>
* 当前存在f1, f2, f3, f4四层窗体则调用方法<br>
* List<String> nameList = new ArrayList<String>();<br>
* nameList.add("f2");<br>
* switchFrame(nameList)<br>
* 此时窗体将回到f2层无需再从顶层开始向下切换<br>
* 注意窗体的切换按照从前向后的顺序进行切换切换顺序不能相反
*
* @param nameList 存储窗体的名称或xpath与css定位方式的List集合
*/
public void switchFrame(List<String> nameList) {
nameList.forEach(name -> {
//判断name指向的窗体是否在iframeNameList中若存在则向上切换父层直到切换到name指向的窗体若不存在则直接切换并添加窗体名称
if (iframeNameList.contains(name)) {
//获取name窗体在iframeNameList中的位置
int index = iframeNameList.indexOf(name);
//获取需要向上切换窗体的次数公式为推断出来
int count = iframeNameList.size() - index - 1;
for (int i = 0; i < count; i++) {
switchParentFrame();
}
} else {
//切换窗体
iframeNameList.add(name);
}
});
}
}
}

View File

@ -1,10 +0,0 @@
package test.javase;
public class TestMakeDirector {
public static void main(String[] args) {
// MakeDirectory.createAllFolder();
MakeDirectory.setSavePath("C:");
MakeDirectory.createAllFolder();
System.out.println("The End");
}
}

View File

@ -1,17 +0,0 @@
package test.javase;
import java.util.HashMap;
import org.testng.annotations.Test;
public class TestMap {
HashMap<String, String> map = new HashMap<String, String>(16);
/**
* 用于测试map移除不存在的元素
*/
@Test
public void removeTest() {
System.out.println(map.remove("hehe"));
}
}

View File

@ -1,16 +0,0 @@
package test.javase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class TestOpenBrowers {
public static void main(String[] args) {
//FirefoxBrower fb = new FirefoxBrower("C:\\Program Files (x86)\\firefox46\\firefox.exe", "http://www.hao123.com");
//WebDriver d = fb.getDriver();
//By by = By.xpath("/html/body/");
//System.out.println(by.toString());
ChromeBrower cb = new ChromeBrower("E:\\chromedriver.exe", "http://www.hao123.com");
WebDriver d = cb.getDriver();
System.out.println("The End");
}
}

View File

@ -1,31 +0,0 @@
package test.javase;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class TestPOI {
public static void main(String[] args) throws FileNotFoundException, IOException {
XSSFWorkbook xw = new XSSFWorkbook(new FileInputStream(new File("D:\\8.test\\TestReadDateFormat\\测试文件.xlsx")));
XSSFSheet xs = xw.getSheetAt(0);
for (int i = 0; i < xs.getLastRowNum() + 1; i++) {
if (xs.getRow(i).getCell(0) == null) {
}
if (xs.getRow(i).getCell(0).getCellTypeEnum() == CellType.NUMERIC
&& !xs.getRow(i).getCell(0).getCellStyle().getDataFormatString().equalsIgnoreCase("General")) {
System.out.println(new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒")
.format(xs.getRow(i).getCell(0).getDateCellValue()));
} else {
System.out.println(xs.getRow(i).getCell(0).toString().replaceFirst("\\.0", ""));
}
System.out.println("-".repeat(11));
}
}
}

View File

@ -1,72 +0,0 @@
package test.javase;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationConstraint;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFDataValidationConstraint;
import org.apache.poi.xssf.usermodel.XSSFDataValidationHelper;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class TestPOIData {
public static void main(String[] args) throws IOException {
// 创建excel文件
XSSFWorkbook xw = new XSSFWorkbook();
XSSFSheet xs1 = xw.createSheet("测试");
XSSFSheet xs2 = xw.createSheet("数据");
xs1.createRow(0);
// 加载下拉列表内容由于Excel对序列有字数的限制无法添加大量的数据进入序列所以需要使用以下的方法实现
XSSFDataValidationConstraint constraint1 =
new XSSFDataValidationConstraint(new String[] { "呵呵", "哈哈", "嘻嘻" });
// 设置数据有效性加载在哪个单元格上,四个参数分别是起始行终止行起始列终止列
CellRangeAddressList regions = new CellRangeAddressList(0, 0, 0, 0);
// 数据有效性对象
DataValidation d = new XSSFDataValidationHelper(xs1).createValidation(constraint1, regions);
xs1.addValidationData(d);
// 创建一列数据
xs2.createRow(0).createCell(0).setCellValue("");
xs2.createRow(1).createCell(0).setCellValue("");
xs2.createRow(2).createCell(0).setCellValue("");
xs2.createRow(3).createCell(0).setCellValue("");
xs2.createRow(4).createCell(0).setCellValue("");
xs2.createRow(5).createCell(0).setCellValue("!");
XSSFRow xr2 = xs1.createRow(1);
// 创建公式约束
DataValidationConstraint constraint2 = new XSSFDataValidationHelper(xs1)
.createFormulaListConstraint("=数据!$A$1:$A$" + String.valueOf(xs2.getLastRowNum() + 1));
// 设置数据有效性加载在哪个单元格上,四个参数分别是起始行终止行起始列终止列
CellRangeAddressList regions2 = new CellRangeAddressList(0, 0, 1, 1);
// 数据有效性对象
DataValidation d2 = new XSSFDataValidationHelper(xs1).createValidation(constraint2, regions2);
xs1.addValidationData(d2);
System.out.println(xs1.getLastRowNum());
File f = new File("E:\\Test\\haha.xlsx");
// 将预设内容写入Excel文件中异常直接处理不抛出
try {
// 定义输出流用于向指定的Excel文件中写入内容
FileOutputStream fop = new FileOutputStream(f);
// 写入文件
xw.write(fop);
// 关闭流
fop.close();
xw.close();
} catch (IOException e) {
e.printStackTrace();
}
java.awt.Desktop.getDesktop().open(f);
}
}

View File

@ -1,18 +0,0 @@
package test.javase;
import pres.auxiliary.tool.string.CarLicecenType;
import pres.auxiliary.tool.string.PresetString;
import pres.auxiliary.tool.string.RandomString;
import pres.auxiliary.tool.string.StringMode;
public class TestPresetStr {
public static void main(String[] args) {
System.out.println("民用车牌:" + PresetString.carLicence());
System.out.println("警用车牌:" + PresetString.carLicence(CarLicecenType.POLICE));
System.out.println("使馆车牌:" + PresetString.carLicence(CarLicecenType.ELCHEE));
System.out.println("新能源汽车车牌:" + PresetString.carLicence(CarLicecenType.ENERGY));
System.out.println("身份证:" + PresetString.IdentityCard());
System.out.println("姓名:" + PresetString.name());
System.out.println("手机号码139" + new RandomString(StringMode.NUM).toString(8));
}
}

View File

@ -1,42 +0,0 @@
package test.javase;
import java.util.Random;
public class TestRandom {
public static void main(String[] args) {
// System.out.println(Math.ceil(3.5));
// System.out.println(0 - new Random().nextInt(90));
// System.out.print("数字:");
// int num = new Scanner(System.in).nextInt();
// System.out.print("数量:");
// int count = new Scanner(System.in).nextInt();
int num = 30000000;
int count = 3;
int[] nums = new int[count];
// 向下取整获得平均数
int avgNum = num / count;
// 向上取整获得差值
int diffNum = (int) Math.ceil(avgNum / 10.0);
int minNum = avgNum - diffNum;
int maxNum = avgNum + diffNum;
int sum = 0;
for (int i = 0; i < count; i++) {
int ranNum = new Random().nextInt(maxNum - minNum + 1) + minNum;
sum += ranNum;
nums[i] = ranNum;
}
nums[new Random().nextInt(count)] -= (sum - num);
sum = 0;
for (int i = 0; i < count; i++) {
System.out.println("" + (i + 1) + "个控件填写:" + nums[i]);
sum += nums[i];
}
}
}

View File

@ -1,153 +0,0 @@
package test.javase;
import pres.auxiliary.tool.string.RandomString;
public class TestRandomString {
public static void main(String[] args) {
RandomString rs = new RandomString();
rs.addMode("asdf");
//System.out.println(rs.getStringSeed());
//System.out.println(rs.toString(50));
System.out.println(rs.getStringSeed());
rs.shuffle();
System.out.println(rs.getStringSeed());
System.out.println("---------------------");
rs.setRepeat(false);
rs.setDispose(rs.DISPOSE_IGNORE);
System.out.println(rs.toString(6));
System.out.println(rs.getStringSeed());
System.out.println("---------------------");
/*
try {
rs.setDispose(rs.DISPOSE_THROW_EXCEPTION);
System.out.println(rs.toString(6));
} catch (LllegalStringLengthException e) {
e.printStackTrace();
}
System.out.println("---------------------");
*/
System.out.println(rs.getStringSeed());
rs.setDispose(rs.DISPOSE_REPEAT);
System.out.println(rs.toString(8));
System.out.println(rs.getStringSeed());
System.out.println("---------------------");
System.out.println(rs.toString(3));
rs.setRepeat(true);
System.out.println(rs.toString(3));
System.out.println("---------------------");
rs.setRepeat(false);
System.out.println(rs.toString(4));
rs.setRepeat(true);
System.out.println(rs.toString(4));
System.out.println("---------------------");
rs.setRepeat(false);
System.out.println(rs.toString(8));
rs.setRepeat(true);
System.out.println(rs.toString(8));
System.out.println("---------------------");
/*
System.out.println("中文名:" + new RandomString(StringMode.CH));
System.out.println("英文名:" + new RandomString(StringMode.CAP));
*/
/*
System.out.println("测试构造方法:");
RandomString rs1 = new RandomString();
System.out.println("无参构造产生的字符串池为:" + rs1.getStringSeed());
RandomString rs2 = new RandomString(StringMode.NUM);
System.out.println("传入大写字母模型的构造产生的字符串池为:" + rs2.getStringSeed());
RandomString rs3 = new RandomString("AThis is my RandomString class");
System.out.println("传入自定义字符串的参构造产生的字符串池为:" + rs3.getStringSeed());
System.out.println("----------------------------------------------");
System.out.println("测试普通方法:");
System.out.println("测试getStringSeed()方法:");
System.out.println(rs2.getStringSeed());
System.out.println();
System.out.println("测试addMode(StringMode... modes)方法:");
System.out.println("rs1调用方法前" + rs1.getStringSeed());
rs1.addMode(StringMode.LOW);
System.out.println("rs1添加LOW模型后" + rs1.getStringSeed());
System.out.println();
System.out.println("测试addMode(boolean isRepeat, StringMode... modes)方法:");
System.out.println("rs1调用方法前" + rs1.getStringSeed());
rs1.addMode(false, StringMode.LOW);
System.out.println("rs1再次添加LOW模型不可重复" + rs1.getStringSeed());
rs1.addMode(true, StringMode.LOW);
System.out.println("rs1再次添加LOW模型可重复" + rs1.getStringSeed());
System.out.println();
System.out.println("测试addMode(String mode)方法:");
System.out.println("rs3调用方法前" + rs3.getStringSeed());
rs3.addMode(" haha");
System.out.println("rs3添加LOW模型后" + rs3.getStringSeed());
System.out.println();
System.out.println("测试addMode(boolean isRepeat, StringMode... modes)方法:");
System.out.println("rs3调用方法前" + rs3.getStringSeed());
rs3.addMode(false, " xixi");
System.out.println("rs3再次添加LOW模型不可重复" + rs3.getStringSeed());
rs3.addMode(true, " hehe");
System.out.println("rs3再次添加LOW模型可重复" + rs3.getStringSeed());
System.out.println();
System.out.println("测试clear()方法:");
System.out.println("rs2调用方法前" + rs2.getStringSeed());
rs2.clear();
System.out.println("rs2调用方法后" + rs2.getStringSeed());
System.out.println();
System.out.println("测试length()方法:");
System.out.println("rs1字符串池中的元素共有" + rs1.length());
System.out.println();
System.out.println("测试remove(String str)方法:");
System.out.println("rs3调用方法前" + rs3.getStringSeed());
rs3.remove("hehe");
System.out.println("rs3移除“hehe”后" + rs3.getStringSeed());
System.out.println();
System.out.println("测试remove(int StartPos, int EndPos)方法:");
System.out.println("rs3调用方法前" + rs3.getStringSeed());
rs3.remove(5, 8);
System.out.println("rs3移除5~7位的元素后" + rs3.getStringSeed());
System.out.println();
System.out.println("测试remove(int Pos)方法:");
System.out.println("rs3调用方法前" + rs3.getStringSeed());
rs3.remove(0);
System.out.println("rs3移除第一位的元素后" + rs3.getStringSeed());
System.out.println();
System.out.println("测试removeRepetition()方法:");
System.out.println("rs3调用方法前" + rs3.getStringSeed());
rs3.removeRepetition();
System.out.println("rs3移除第一位的元素后" + rs3.getStringSeed());
System.out.println();
System.out.println("测试toString()方法:");
System.out.println("rs3调用方法" + rs3.toString());
System.out.println();
System.out.println("测toString(int stringLength)方法:");
System.out.println("rs3调用方法" + rs3.toString(8));
System.out.println();
System.out.println("测试toString(int stringLengthMin, int stringLengthMax)方法:");
System.out.println("rs3调用方法" + rs3.toString(1, 4));
System.out.println();
*/
}
}

View File

@ -1,90 +0,0 @@
package test.javase;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
public class TestReadWordTable {
public static void main(String[] args) throws IOException {
readWeekReport(new File("E:\\test.docx"));
}
public static void readWeekReport(File report) throws IOException {
// 使用POI中的读取word文件的方法
XWPFDocument xd = new XWPFDocument(new FileInputStream(report));
//记录重要信息
//报告人姓名
String name = "";
//报告开始时间
String startTime = "";//可能不需要
Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_WEEK, 6);
c.add(Calendar.WEEK_OF_MONTH, -1);
c.add(Calendar.DATE, 1);
System.out.println(new SimpleDateFormat("YYYY-MM-dd").format(c.getTime()));
//工作内容
String content = "";
//工作天数
String day = "";
List<XWPFTable> tables = xd.getTables();// 得到word中的表格
// 循环获取文档中所有的表格
for ( int a = 0; a < tables.size(); a++ ) {
// 获取表格中的所有行
List<XWPFTableRow> rows = tables.get(a).getRows();
// 循环用于获取行中所有的列
for (int i = 0; i < rows.size(); i++) {
List<XWPFTableCell> cells = rows.get(i).getTableCells();
// 用于获取列中所有的段
for (int j = 0; j < cells.size(); j++) {
List<XWPFParagraph> paras = cells.get(j).getParagraphs();
// 用于读取段中所有的文字
for (int k = 0; k < paras.size(); k++) {
//读取第一个表格第3行第2列姓名
if ( a == 0 && i == 2 && j == 1 ) {
name = paras.get(k).getText();
}
//读取工作内容
if( a == 1 && i > 0 && j == 2 ) {
content += paras.get(k).getText();
content += "*";
}
//读取工作天数
if( a == 1 && i > 0 && j == 3 ) {
day += paras.get(k).getText();
day += "*";
}
}
}
}
}
//删除最后一个*
content.substring(0, content.lastIndexOf("*"));
day.substring(0, day.lastIndexOf("*"));
xd.close();
}
private static void writeSummarySheet(File templet) {
}
}

View File

@ -1,90 +0,0 @@
package test.javase;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestSe {
public static void main(String[] args) throws InterruptedException {
//TestPrintBrowserInfomation();
Test_1();
}
public static void TestPrintBrowserInfomation() {
//若火狐路径在默认位置且不需要使用配置文件时可直接使用以下代码以下代码作用为打开火狐浏览器
FirefoxDriver driver = new FirefoxDriver();
//巨大化浏览器
driver.manage().window().maximize();
//打开待测试的网址注意网址一定要加上http://否则无法进入
driver.get("http://www.hao123.com");
System.out.println(driver.getPageSource());//输出HTML代码
System.out.println("-------------------------------------------------------");
System.out.println(driver.getCurrentUrl());//输出网址
System.out.println("-------------------------------------------------------");
System.out.println(driver.getCapabilities().getVersion());//输出浏览器版本
System.out.println("-------------------------------------------------------");
System.out.println(driver.getCapabilities().getBrowserName());//输出浏览器名称
System.out.println("-------------------------------------------------------");
System.out.println(driver.getCapabilities().getPlatform().name());//输出操作系统名称
System.out.println("-------------------------------------------------------");
System.out.println(driver.getCapabilities().getPlatform().getMajorVersion());//输出操作系统版本
System.out.println("-------------------------------------------------------");
driver.close();
}
public static void Test_1() throws InterruptedException {
//若火狐路径不在默认位置时需要使用该代码来找到火狐的位置
//System.setProperty("webdriver.firefox.bin", "D:\\firefox\\firefox.exe");
//若需要使用配置时即在火狐中创建的配置文件需要用到该行代码
//ProfilesIni pi = new ProfilesIni();
//FirefoxProfile profile = pi.getProfile("pyqone");
//WebDriver driver = new FirefoxDriver(profile);
//若火狐路径在默认位置且不需要使用配置文件时可直接使用以下代码以下代码作用为打开火狐浏览器
WebDriver driver = new FirefoxDriver();
//巨大化浏览器
driver.manage().window().maximize();
//打开待测试的网址注意网址一定要加上http://否则无法进入
driver.get("http://www.hao123.com");
//获取待测页面上的文本框定位
//一般使用xpath定位和css定位获取方式为使用火狐进行获取
//findElement()方法表示查找定位方式所对应的元素
//By.xpath()表示使用xpath方式来定位此时复制的最简xpath
//sendKeys()方法表示在控件中输入信息
//以下代码的作用为在hao123的百度搜索文本框中输入QQ
WebElement element = driver.findElement(By.xpath("//*[@id=\"search-input\"]"));
((JavascriptExecutor) driver).executeScript("arguments[0].setAttribute('style',arguments[1])", element,"background:yellow;solid:red;");
element.sendKeys("QQ");
Thread.sleep(5000);
//System.out.println(driver.findElement(By.xpath("//*[@id=\"search-input\"]")).getAttribute("value"));
System.out.println(driver.findElement(By.xpath("/html/body/div[2]/div[2]/div/div[1]/div[2]/div/div/div[1]/a")).getTagName());
System.out.println(driver.findElement(By.xpath("/html/body/div[2]/div[2]/div/div[1]/div[2]/div/div/div[1]/a")).getAttribute("value"));
/*
String js = "var s = document.getElementById(\"search-input\");";
js += "return s.nodeValue";
System.out.println(((JavascriptExecutor) driver).executeScript(js));
*/
//以上代码等价于此时用的完整xpath来定位
//driver.findElement(By.xpath("/html/body/div[2]/div[2]/div/div[1]/div[2]/div/div/div[1]/div[3]/form/div[1]/div/input")).sendKeys("QQ");
//也等价于此时用的是CSS方式定位
//driver.findElement(By.cssSelector("html body div#skinroot.sk_skin-color-green div.layout-container.s-sbg1 div.layout-container-inner.s-sbg2 div div.hao123-search-panel-box div#hao123-search-panel.g-wd.page-width.hao123-search-panel div.hao123-search.hao123-indexsearchlist1 div#search.search div.right.form-wrapper form#search-form.form-hook div.input-wrapper.wrapper-hook.g-ib div.input-shadow.shadow-hook.g-ib input#search-input.input.input-hook")).sendKeys("QQ");
/*
//点击hao123页面上的百度一下按钮
driver.findElement(By.xpath("//*[@value=\"百度一下\"]")).click();
//等价于
WebElement w = driver.findElement(By.xpath("//*[@value=\"百度一下\"]"));
w.click();
//关闭浏览器
driver.close();
*/
}
}

View File

@ -1,50 +0,0 @@
package test.javase;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestSelenium {
public static void main(String[] args) {
//固定写法第一个参数指定的是你使用的浏览器第二个参数是谷歌浏览器驱动路径
System.setProperty("webdriver.chrome.driver", "Resource/BrowersDriver/chromedriver.exe");
//new对象
ChromeDriver driver = new ChromeDriver();
//打开浏览器并进入指定的站点
//注意http://不能省略
driver.get("https://www.hao123.com/");
//全屏浏览器
driver.manage().window().maximize();
//设置加载时间一下代码的含义是若页面在30秒内加载不出则抛出异常
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
//获取页面title
System.out.println(driver.getTitle());
//在百度搜索文本框中输入abc点击百度一下
driver.findElement(By.xpath("//*[@id=\"search\"]/form/div[2]/input")).sendKeys("abc");
driver.findElement(By.xpath("//*[@id=\"search\"]/form/div[3]/input")).click();
//点击id属性为test的元素
driver.findElement(By.id("test")).click();
//点击有超链接的中国网的元素
driver.findElement(By.linkText("中国网")).click();
//点击name属性为"word"的元素
driver.findElement(By.name("word")).click();
//点击html标签名为input的元素
driver.findElement(By.tagName("input")).click();
//点击xpath为//*[@id=\"search\"]/form/div[3]/input”的元素常用
driver.findElement(By.xpath("//*[@id=\"search\"]/form/div[3]/input")).click();
//点击css选择器为html body.sk_skin-color-green div.index-page-inner ewc s-sbg2的元素常用
driver.findElement(By.cssSelector("html body.sk_skin-color-green div.index-page-inner ewc s-sbg2")).click();
//点击class属性为searchWrapper的元素
driver.findElement(By.className("searchWrapper")).click();
//div[1]/div[1]/form
//双击事件
//Actions a = new Actions(driver);
//a.doubleClick(driver.findElement(By.xpath("//*[@id=\"search\"]/form/div[3]/input"))).perform();
//关闭浏览器
//driver.close();
}
}

View File

@ -1,46 +0,0 @@
package test.javase;
import java.io.File;
public class TestUseClass {
public static void main(String[] args) {
TestUseAClass ta = new TestUseAClass(
new File("E:\\pyq\\TFS\\品管部工作\\05.日常管理\\个人工作\\彭宇琦\\2018年工作周报\\NNCQ_彭宇琦_第35周个人周报(C899).docx"));
TestUseBClass tb = new TestUseBClass(ta);
System.out.println(tb.test());
ta.setF(new File("E:\\pyq\\TFS\\品管部工作\\05.日常管理\\个人工作\\彭宇琦\\2018年工作周报\\NNCQ_彭宇琦_第42周个人周报.docx"));
System.out.println(tb.test());
}
}
class TestUseAClass {
public File f;
public TestUseAClass(File f) {
super();
this.f = f;
}
public File getF() {
return f;
}
public void setF(File f) {
this.f = f;
}
}
class TestUseBClass {
public TestUseAClass ta;
public TestUseBClass(TestUseAClass ta) {
super();
this.ta = ta;
}
public String test() {
return ta.getF().getName();
}
}

View File

@ -1,7 +0,0 @@
package test.javase;
public class TestWriteCaseUI {
public static void main(String[] args) {
WriteCaseMainFrame.Main();
}
}

View File

@ -1,32 +0,0 @@
package test.javase;
import java.io.IOException;
import org.dom4j.DocumentException;
import pres.auxiliary.report.ui.TestReportMainFrame;
public class TestWriteReport {
public static void main(String[] args) throws IOException, DocumentException, InterruptedException {
// 创建测试报告类
//TestReport r = new TestReport();
//r.AutoWriteReport(true, true);
// r.setSavePath("E:\\");
// 测试报告属性作为参数传入createReport()
//r.createReport(new File("E:\\1 - 副本.csv"), 2, "彭宇琦、李健梅、赵莉宽", "页面所有功能及APP任务、消息提醒功能");
// System.out.println(r.getMailContent());
TestReportMainFrame.Main();
/*
File f = new File("E:\\1.csv");
TestReport r = new TestReport();
String[] ss = r.readFile(f, 4);
for ( String s : ss ) {
System.out.println(s);
}
*/
System.out.println("The end");
}
}

View File

@ -1,11 +0,0 @@
package test.javase;
import pres.auxiliary.work.selenium.tool.Log_Old;
public class testResultFile {
public static void main(String[] args) {
Log_Old trf = new Log_Old();
trf.setSavePath("\\a");
}
}

View File

@ -1,13 +0,0 @@
package test.javase;
import java.io.File;
import pres.auxiliary.work.old.testcase.change.WriteTestCase;
public class testWriteTestCase {
public static void main(String[] args) throws Exception {
WriteTestCase wtc = new WriteTestCase(new File("E:\\test.xml"));
wtc.write();
System.out.println("The End");
}
}

View File

@ -1,39 +0,0 @@
package test.javase;
import org.dom4j.DocumentException;
public class testxml {
public static void main(String[] args) throws XmlFileNameIsNullException, DocumentException {
/*
List<String> l = new ArrayList<>();
l.add("帐号文本框");
l.add("密码文本框");
l.add("登录按钮");
CreateXML.setXmlPath("xml");
CreateXML.setXmlName("登录界面");
CreateXML.create("帐号文本框", "密码文本框", "登录按钮");
CreateXML.create("登录界面2", l);
*/
/*
File f = new File("C:\\AutoTestting\\Xml\\ElementName");
CreateXML.setMode(CreateXML.XPATH, CreateXML.CSS, CreateXML.NAME);
CreateXML.create(f.listFiles());
*/
/*
String s = "测试模块1(#949)";
System.out.println(s.substring(0, s.indexOf("(")));
System.out.println(s.substring(s.indexOf("(") + 2, s.indexOf(")")));
*/
/*
Document dom = new SAXReader().read(new File("C:\\AutoTest\\Case\\ZentaoData.xml"));
Element e = (Element)dom.selectSingleNode("/data/module[@name='新能源共享汽车后台管理系统']");
System.out.println(e.attribute("id").getValue());
*/
System.out.println(Boolean.valueOf(""));
}
}

View File

@ -1,38 +0,0 @@
package test.selenium.brower;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
/**
* <p><b>文件名</b>TestOpenBrower.java</p>
* <p><b>用途</b>用于实验打开各类浏览器</p>
* <p><b>编码时间</b>2020年11月8日 下午2:49:54</p>
* <p><b>修改时间</b>2020年11月8日 下午2:49:54</p>
* @author 彭宇琦
* @version Ver1.0
* @since JDK 12
*/
public class TestOpenBrower {
WebDriver driver;
@AfterClass
public void quit() {
driver.quit();
}
@Test
public void openIeBrower() {
// File ieDriverFile = new File("Resource/BrowersDriver/Ie/IEDriverServer.exe");
// 指定IE driver的存放路径
System.setProperty("webdriver.ie.driver", "Resource/BrowersDriver/Ie/IEDriverServer.exe");
InternetExplorerOptions ieo = new InternetExplorerOptions();
//实例化webdriver对象启动IE浏览器
driver = new InternetExplorerDriver();
//通过对象driver调用具体的get方法来打开网页
driver.get("http://www.baidu.com/");
}
}

View File

@ -1,103 +0,0 @@
package test.selenium.brower;
import java.util.Set;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TestOpenNewHandle {
ChromeDriver cd;
@BeforeClass
public void openBrower() {
System.setProperty("webdriver.chrome.driver", "Resource/BrowersDriver/Chrom/78.0394.70/chromedriver.exe");
cd = new ChromeDriver();
cd.get("http://www.baidu.com");
}
@AfterClass
public void quitBrower() throws InterruptedException {
Thread.sleep(5000);
cd.quit();
}
/**
* 覆盖原标签页
* @throws InterruptedException
*/
@Test
public void overridePage() throws InterruptedException {
cd.get("http://www.baidu.com");
Thread.sleep(2000);
cd.get("about:blank");
cd.switchTo().window("");
}
/**
* 打开新的标签页
* @throws InterruptedException
*/
@Test
public void openNewLabel() throws InterruptedException {
//获取当前所有的handle
Set<String> handleSet = cd.getWindowHandles();
//编写js脚本执行js以开启一个新的标签页
String js = "window.open(\"\");";
cd.executeScript(js);
//移除原有的windows的Handle保留新打开的windows的Handle
String newHandle = "";
for (String handle : cd.getWindowHandles()) {
if (!handleSet.contains(handle)) {
newHandle = handle;
break;
}
}
//切换WebDriver
cd.switchTo().window(newHandle);
Thread.sleep(2000);
// cd.get("http://www.hao123.com");
}
/**
* 打开新的浏览器
*/
@Test
public void openNewBrower() {
//关闭原有的浏览器
cd.quit();
//重新构造并进入待测站点
System.setProperty("webdriver.chrome.driver", "Resource/BrowersDriver/chromedriver.exe");
cd = new ChromeDriver();
cd.get("http://www.163.com");
}
/**
* 覆盖原标签页
* @throws InterruptedException
*/
@Test
public void closeLabel() throws InterruptedException {
cd.get("http://www.baidu.com");
Thread.sleep(2000);
//获取当前所有的handle
Set<String> handleSet = cd.getWindowHandles();
//编写js脚本执行js以开启一个新的标签页
String js = "window.open(\"\");";
cd.executeScript(js);
//移除原有的windows的Handle保留新打开的windows的Handle
String newHandle = "";
for (String handle : cd.getWindowHandles()) {
if (!handleSet.contains(handle)) {
newHandle = handle;
break;
}
}
cd.close();
cd.switchTo().window(newHandle);
cd.get("http://www.163.com");
}
}

View File

@ -1,51 +0,0 @@
package test.selenium.brower;
import java.util.Set;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestSwitchWindow {
public static void main(String[] args) throws InterruptedException {
TestDriver td = new TestDriver();
ChromeDriver cd = td.getDriver();
td.open();
cd.get("http://www.hao123.com");//页面在第二个标签页中被打开
Thread.sleep(5000);
cd.quit();
}
public static class TestDriver {
ChromeDriver cd;
public TestDriver() {
System.setProperty("webdriver.chrome.driver", "Resource/BrowersDriver/chromedriver.exe");
cd = new ChromeDriver();
cd.get("http://www.baidu.com");
}
public void open() {
//获取当前所有的handle
Set<String> handleSet = cd.getWindowHandles();
//编写js脚本执行js以开启一个新的标签页
String js = "window.open(\"https://www.sogou.com\");";
cd.executeScript(js);
//移除原有的windows的Handle保留新打开的windows的Handle
String newHandle = "";
for (String handle : cd.getWindowHandles()) {
if (!handleSet.contains(handle)) {
newHandle = handle;
break;
}
}
//切换WebDriver
cd.switchTo().window(newHandle);
}
public ChromeDriver getDriver() {
return cd;
}
}
}

View File

@ -1,54 +0,0 @@
package test.selenium.js;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import pres.auxiliary.work.selenium.brower.ChromeBrower;
import pres.auxiliary.work.selenium.brower.ChromeBrower.ChromeOptionType;
public class TestJavaScript {
@Test
public void getElementAttribute() {
ChromeBrower cb = new ChromeBrower(new File("Resource/BrowersDriver/Chrom/80.0.3987.163/chromedriver.exe"));
cb.addConfig(ChromeOptionType.CONTRAL_OPEN_BROWER, "127.0.0.1:9222");
JavascriptExecutor js = (JavascriptExecutor) cb.getDriver();
WebElement element = cb.getDriver().findElement(By.xpath("//*[@id='kw']"));
JSONObject elemrntJson = new JSONObject();
elemrntJson.put("tagname", element.getTagName());
JSONArray attArray = new JSONArray();
((ArrayList<Object>) js.executeScript("return arguments[0].attributes;", element)).stream().
map(obj -> obj.toString()).map(text -> {
String[] atts = text.split("\\,\\ ");
JSONObject json = new JSONObject();
Arrays.stream(atts).filter(att -> {
String key = att.split("=")[0];
return "name".equals(key) || "value".equals(key);
}).forEach(att -> {
String[] kv = att.split("=");
json.put(kv[0], kv[1].indexOf("}") > -1 ? kv[1].substring(0, kv[1].length() - 1) : kv[1]);
});
return json;
}).forEach(json -> {
attArray.add(json);
});
elemrntJson.put("att", attArray);
System.out.println(elemrntJson);
cb.getDriver().quit();
}
}