关于import org.apache.xpath.XPathAPI;

本文介绍如何导入Apache Xalan的Xalan.jar包,用于XPath处理。提供了下载地址及解压导入步骤。
import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.RemoteWebDriver; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import java.io.IOException; import java.util.Collections; import java.util.HashMap; /** * 解析用例测试类 * * @since 2021-09-16 */ @PowerMockIgnore({"javax.management.*", "javax.crypto.*"}) // 忽略异常 @PrepareForTest({ FileUtils.class, FileServiceManager.class}) @RunWith(PowerMockRunner.class) public class SeleniumActionTest { private SeleniumAction seleniumAction = new SeleniumAction(); /** * 测试用例描述:测试获取webDriver * 预制条件:RemoteWebDriver * 操作步骤:执行get方法 * 预期结果:抛异常 */ @Test public void testGetWebDriver() throws Exception { PowerMockito.whenNew(RemoteWebDriver.class).withAnyArguments().thenReturn(null); Assert.assertThrows(Error.class, () -> seleniumAction.getWebDriver()); } /** * 测试用例描述:测试执行方法 * 预制条件:Action对象 * 操作步骤:调用execute方法 * 预期结果:抛指定异常 */ @Test public void testExecute() throws IOException { Action action = new Action(); action.setCommand("openUrl"); action.setValue("http://www.baidu.com"); action.setUrl("file://etc"); Action.Path path = new Action.Path(); path.setId("id"); path.setName("name"); path.setXpath(Collections.singletonList("/xpath")); path.setCss(Collections.singletonList("/css")); path.setControlType("adc"); action.setPath(path); WebDriver driver = PowerMockito.mock(RemoteWebDriver.class); WebElement webElement = PowerMockito.mock(WebElement.class); PowerMockito.when(webElement.isDisplayed()).thenReturn(true); PowerMockito.when(driver.findElement(By.id("id"))).thenThrow(new NoSuchElementException("")); PowerMockito.when(driver.findElement(By.name("name"))).thenThrow(new NoSuchElementException("")); PowerMockito.when(driver.findElement(By.xpath("/xpath"))).thenThrow(new NoSuchElementException("")); PowerMockito.when(driver.findElement(By.cssSelector("/css"))).thenReturn(webElement); PowerMockito.mockStatic(FileUtils.class); PowerMockito.when(FileUtils.openInputStream(Mockito.any())).thenReturn(null); FileService fileService = PowerMockito.mock(FileService.class); PowerMockito.mockStatic(FileServiceManager.class); PowerMockito.when(FileServiceManager.getSystemFileService()).thenReturn(fileService); Assert.assertThrows(ExceptionInInitializerError.class, () -> seleniumAction.execute(driver, action, new HashMap<>(), new HashMap<>(), "AAA", "2000")); } } 把powermockito改成mockito
最新发布
11-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值