ChengYuXuan %!s(int64=5) %!d(string=hai) anos
pai
achega
49e519e092

+ 0 - 6
pom.xml

@@ -73,12 +73,6 @@
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.seleniumhq.selenium</groupId>
-            <artifactId>selenium-java</artifactId>
-            <scope>test</scope>
-            <version>3.14.0</version>
-        </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>

+ 0 - 30
src/test/README.md

@@ -1,30 +0,0 @@
-# 测试说明文档
-
-## 前端测试
-
-使用 Selenium 测试框架,需要配置对应浏览器的 driver
-
-示例文件为 `TestBase.java` 和 `TestBrowser.java`
-
-### 配置 driver
-
-根据自己电脑上的浏览器配置对应 driver,示例如下 `TestBase.java`
-
-假如本机已经安装 Firefox 浏览器,需要安装对应的 driver 名为 geckodriver
-
-从网上下载对应系统的 driver 后,根据存放路径配置
-
-其他浏览器以及对应的 driver 可从 Selenium 官方文档查找
-
-```java
-public class TestBase {
-    public void startBrowser() {
-        System.setProperty("webdriver.gecko.driver", "C://geckodriver.exe"); // 配置 driver 的路径
-        driver = new FirefoxDriver();
-    }
-}
-```
-
-### 编写测试代码
-
-参见 `TestBrowser.java`

+ 0 - 21
src/test/java/cn/seecoder/courselearning/TestBase.java

@@ -1,21 +0,0 @@
-package cn.seecoder.courselearning;
-
-import org.openqa.selenium.WebDriver;
-import org.openqa.selenium.firefox.FirefoxDriver;
-
-public class TestBase {
-    public static WebDriver driver;
-
-    public void startBrowser() {
-//        System.setProperty("webdriver.firefox.bin", "/usr/bin/firefox");
-        System.setProperty("webdriver.gecko.driver", "src/main/resources/geckodriver.exe");
-        System.setProperty("url", "http://localhost:8080");
-        driver = new FirefoxDriver();
-    }
-
-    public static WebDriver getDriver() {
-        return driver;
-    }
-
-}
-

+ 0 - 106
src/test/java/cn/seecoder/courselearning/TestBrowser.java

@@ -1,106 +0,0 @@
-package cn.seecoder.courselearning;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.openqa.selenium.*;
-
-import java.util.concurrent.TimeUnit;
-
-public class TestBrowser {
-
-    public static String deployUrl;
-
-    public static WebDriver driver;
-
-    //实例化TestBase的对象,以方便调用其中的方法
-    static TestBase base = new TestBase();
-
-    @Before
-    public void init(){
-        base.startBrowser();
-        driver = TestBase.getDriver();
-
-        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
-        deployUrl = System.getProperty("url");
-        driver.get(deployUrl);
-        driver.manage().window().setPosition(new Point(100, 50));
-        driver.manage().deleteAllCookies();
-        driver.manage().window().maximize();
-    }
-
-    /**
-     * 充值123,充值成功
-     */
-    @Test
-    public void test1() throws Exception {
-        try {
-            driver.findElement(By.xpath("/html/body/div/div/div/div/header/div/button[2]")).click();
-            driver.findElement(By.xpath("/html/body/div/div/div/div/div/div/form/div[1]/div/div[1]/div/input")).sendKeys("10212345678");
-            driver.findElement(By.xpath("/html/body/div/div/div/div/div/div/form/div[2]/div/div[1]/div/input")).sendKeys("123456");
-            driver.findElement(By.xpath("/html/body/div/div/div/div/div/div/form/button")).click();
-            Thread.sleep(1000);
-            driver.findElement(By.xpath("/html/body/div/div[1]/div/div/header/div/button[2]")).click();
-            driver.findElement(By.xpath("/html/body/div/div[2]/div/div[2]")).click();
-            // 记录充值前的余额
-            int beforeRecharge = Integer.parseInt(driver.findElement(By.xpath("/html/body/div/div[1]/div/div/div/div[3]/form/div[6]/div/div[1]/div/input")).getAttribute("value"));
-            int rechargeNum = 123;
-
-            driver.findElement(By.xpath("/html/body/div/div[1]/div/div/div/div[3]/form/button")).click();
-            driver.findElement(By.xpath("/html/body/div/div[4]/div/div/div[2]/div/div[1]/div/input")).sendKeys(Keys.BACK_SPACE);
-            driver.findElement(By.xpath("/html/body/div/div[4]/div/div/div[2]/div/div[1]/div/input")).sendKeys(String.valueOf(rechargeNum));
-            driver.findElement(By.xpath("/html/body/div/div[4]/div/div/div[3]/button[1]")).click();
-
-            WebElement element = driver.findElement(By.xpath("/html/body/div/div[1]/div/div/div/div[1]/div/div"));
-            Assert.assertTrue(element.isDisplayed()); // 显示提示:“充值成功”
-            // 充值后的余额
-            int afterRecharge = Integer.parseInt(driver.findElement(By.xpath("/html/body/div/div[1]/div/div/div/div[3]/form/div[6]/div/div[1]/div/input")).getAttribute("value"));
-            int diff = afterRecharge - beforeRecharge;
-            Assert.assertEquals(rechargeNum, diff); // 充值前后差额==充值金额
-        } catch (Exception e) {
-            e.printStackTrace();
-            System.out.println("充值异常");
-        }
-    }
-
-    /**
-     * 充值-123,充值失败
-     */
-    @Test
-    public void test2() throws Exception {
-        try {
-            driver.findElement(By.xpath("/html/body/div/div/div/div/header/div/button[2]")).click();
-            driver.findElement(By.xpath("/html/body/div/div/div/div/div/div/form/div[1]/div/div[1]/div/input")).sendKeys("10212345678");
-            driver.findElement(By.xpath("/html/body/div/div/div/div/div/div/form/div[2]/div/div[1]/div/input")).sendKeys("123456");
-            driver.findElement(By.xpath("/html/body/div/div/div/div/div/div/form/button")).click();
-            Thread.sleep(1000);
-            driver.findElement(By.xpath("/html/body/div/div[1]/div/div/header/div/button[2]")).click();
-            driver.findElement(By.xpath("/html/body/div/div[2]/div/div[2]")).click();
-
-            int beforeRecharge = Integer.parseInt(driver.findElement(By.xpath("/html/body/div/div[1]/div/div/div/div[3]/form/div[6]/div/div[1]/div/input")).getAttribute("value"));;
-            int rechargeNum = -123;
-
-            driver.findElement(By.xpath("/html/body/div/div[1]/div/div/div/div[3]/form/button")).click();
-            driver.findElement(By.xpath("/html/body/div/div[4]/div/div/div[2]/div/div[1]/div/input")).sendKeys(Keys.BACK_SPACE);
-            driver.findElement(By.xpath("/html/body/div/div[4]/div/div/div[2]/div/div[1]/div/input")).sendKeys(String.valueOf(rechargeNum));
-            driver.findElement(By.xpath("/html/body/div/div[4]/div/div/div[3]/button[1]")).click();
-
-            WebElement element = driver.findElement(By.xpath("/html/body/div/div[1]/div/div/div/div[1]/div/div"));
-            Assert.assertFalse(element.isDisplayed()); // 不可以充值负数,因此不应当显示“充值成功”
-
-            int afterRecharge = Integer.parseInt(driver.findElement(By.xpath("/html/body/div/div[1]/div/div/div/div[3]/form/div[6]/div/div[1]/div/input")).getAttribute("value"));;
-            int diff = afterRecharge - beforeRecharge;
-            Assert.assertEquals(0, diff); // 充值前后结果应当没变
-        } catch (Exception e) {
-            System.out.println("充值异常");
-        }
-    }
-
-
-    @After
-    public void closeBrowser() {
-        //退出浏览器
-        driver.quit();
-    }
-}