mac自带自动化java_mac java+selenium 实现UI自动化2_琉璃

本文介绍了如何在Mac环境下,利用Java和Selenium进行UI自动化测试。通过导入JXL.jar包,读取Excel数据,实现对网页元素的点击、输入等操作,并创建测试报告记录测试结果。在执行过程中,遇到的Excel格式问题和解决办法也被详细说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用excel驱动的话首先要下载JXL.jar包,导入maven项目中,可以直接拖到resouces里,然后右键add as library;然后把excel文件也同样拖到resouces里,然后代码编写获取路径;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.ExpectedCondition;

import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.BufferedWriter;

import java.io.FileWriter;

import java.util.Date;

import java.io.File;

import java.io.IOException;

import java.text.SimpleDateFormat;

public class Test {

public String time = null;//创建测试结果报告保存到本地

public void createReport() throws IOException {

SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式

time=df.format(new Date());

File parentDir = new File("/Users/liuli/Desktop/UIreport");//报告存储的文件地址

parentDir.mkdir();

String hash = "Report_" + time;

String fileName = hash + ".txt";

File file = new File(parentDir, fileName);

try {

file.createNewFile();

System.out.print("create report successful!");

}

catch (IOException e){

throw new IOException("Exception: " + e);

}

}

//把元素以属性来分类编写入方法,然后遍历excel去读取详细的元素

public void buttonClick_xpath(String path,ChromeDriver driver) throws IOException {

try{

if (driver.findElement(By.xpath(path))!=null){

driver.findElement(By.xpath(path)).click();

writeToFile(path, "is clicked");

}

else {

writeToFile(path,"is not found");

}

}catch (IOException e){

e.printStackTrace();

}

}

/* public void buttonClick_id(String path,ChromeDriver driver) throws IOException {

try{

if (driver.findElement(By.id(path))!=null){

driver.findElement(By.id(path)).click();

<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值