国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

博客系統(tǒng)實(shí)現(xiàn)自動(dòng)化測(cè)試

這篇具有很好參考價(jià)值的文章主要介紹了博客系統(tǒng)實(shí)現(xiàn)自動(dòng)化測(cè)試。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

目錄

一、設(shè)計(jì)博客系統(tǒng)的測(cè)試用例

二、利用測(cè)試用例進(jìn)行測(cè)試?

測(cè)試登錄頁(yè)面

界面測(cè)試?

功能測(cè)試

測(cè)試博客列表頁(yè)?

界面測(cè)試

功能測(cè)試?

測(cè)試博客詳情頁(yè)?

界面測(cè)試

功能測(cè)試

博客編輯頁(yè)測(cè)試

界面測(cè)試

功能測(cè)試?


一、設(shè)計(jì)博客系統(tǒng)的測(cè)試用例

基于博客系統(tǒng)寫測(cè)試用例,軟件測(cè)試,junit,java,單元測(cè)試

二、利用測(cè)試用例進(jìn)行測(cè)試?

測(cè)試的文件放在maven項(xiàng)目的test文件夾下,需要在之前的maven項(xiàng)目中添加一些自動(dòng)化測(cè)試的依賴:

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.0.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.8.2</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-suite -->
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-suite</artifactId>
            <version>1.8.2</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-reporting -->
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-reporting</artifactId>
            <version>1.8.2</version>
        </dependency>

測(cè)試登錄頁(yè)面

首先定義start方法和close方法,并利用相關(guān)注解使其在測(cè)試之前和測(cè)試之后都執(zhí)行一次。

    @BeforeAll
    public void start(){
        driver = getDriver();
        driver.get("http://43.143.208.132:8080/blog_system/blog-login.html");
        //使用隱式等待渲染頁(yè)面完成
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
    }
    @AfterAll
    public void close(){
        driver.quit();
    }

界面測(cè)試?

首先來(lái)測(cè)試界面的文字信息以及頁(yè)面的元素布局是否正確。

public class InterfaceTest {
    public static ChromeDriver driver;
    public static ChromeDriver getDriver(){
        if(driver == null){
            synchronized (PrepareTest.class){
                if(driver == null){
                    driver = new ChromeDriver();
                }
            }
        }
        return driver;
    }
    @BeforeAll
    public  static void start(){
        driver = getDriver();
        driver.get("http://43.143.208.132:8080/blog_system/blog-login.html");
        //使用隱式等待渲染頁(yè)面完成
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
    }
    @AfterAll
    public static  void close(){
        driver.quit();
    }
    /**
     * 測(cè)試登陸文字
     */
    @Test
    public void testDengLu(){
       String dengLu =  driver.findElement(By.xpath("/html/body/div[2]/div/h3")).getText();
        Assertions.assertEquals(dengLu,"登錄");
    }

    /**
     * 測(cè)試提交按鈕的文字
     */
    @Test
    public void testTiJiao(){
        String tiJiao =  driver.findElement(By.xpath("http://*[@id=\"submit\"]")).getAttribute("value");
        Assertions.assertEquals(tiJiao,"提交");
    }

    /**
     * 測(cè)試用戶名輸入框
     */
    @Test
    public void testUserInput(){
        WebElement webElement =  driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input"));
        Assertions.assertNotNull(webElement);
    }
    /**
     * 測(cè)試密碼輸入框
     */
    @Test
    public void testPasswordInput(){
        WebElement webElement =  driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input"));
        Assertions.assertNotNull(webElement);
    }
    /**
     * 測(cè)試提交按鈕
     */
    @Test
    public void testSubmit(){
        WebElement webElement =  driver.findElement(By.xpath("http://*[@id=\"submit\"]"));
        Assertions.assertNotNull(webElement);
    }
}

?基于博客系統(tǒng)寫測(cè)試用例,軟件測(cè)試,junit,java,單元測(cè)試

功能測(cè)試

測(cè)試輸入正確的用戶名和密碼、錯(cuò)誤的用戶名或密碼以及空的用戶名或密碼來(lái)查看是否會(huì)跳轉(zhuǎn)到博客列表頁(yè)。?

測(cè)試正確的用戶名和密碼:

/**
     * 測(cè)試正確登錄
     */
    @ParameterizedTest
    @CsvSource(value = {"zhangsan,1234","zhangyi,1234"})
    public void testLoginTrue(String user,String password){
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).sendKeys(user);
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).sendKeys(password);
        driver.findElement(By.xpath("http://*[@id=\"submit\"]")).click();
       String url = driver.getCurrentUrl();
        Assertions.assertEquals(url,"http://43.143.208.132:8080/blog_system/blog-list.html");
        driver.navigate().back();
    }

基于博客系統(tǒng)寫測(cè)試用例,軟件測(cè)試,junit,java,單元測(cè)試??

測(cè)試用戶名或密碼為空:?

/**
     * 測(cè)試用戶名或密碼為空
     */
    @ParameterizedTest
    @CsvSource(value = {"zhangyi,",",1234",","})
    public void testLoginNull(String user,String password){
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).clear();
        if(user != null){
            driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).sendKeys(user);
        }
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).clear();
        if(password != null){
            driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).sendKeys(password);
        }
        driver.findElement(By.xpath("http://*[@id=\"submit\"]")).click();
        String tips = driver.findElement(By.xpath("/html/body")).getText();
        Assertions.assertEquals("用戶名或密碼不能為空",tips);
        driver.navigate().back();
    }

基于博客系統(tǒng)寫測(cè)試用例,軟件測(cè)試,junit,java,單元測(cè)試

測(cè)試用戶名或密碼錯(cuò)誤:

/**
     * 測(cè)試用戶名或密碼錯(cuò)誤
     */
    @ParameterizedTest
    @CsvSource(value = {"zhangyi,6781","liuyy,1234"})
    public void testLoginFalse(String user,String password){
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).sendKeys(user);
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).sendKeys(password);
        driver.findElement(By.xpath("http://*[@id=\"submit\"]")).click();
        String tips = driver.findElement(By.xpath("/html/body")).getText();
        Assertions.assertEquals("用戶名或密碼錯(cuò)誤",tips);
        driver.navigate().back();
    }

基于博客系統(tǒng)寫測(cè)試用例,軟件測(cè)試,junit,java,單元測(cè)試

測(cè)試博客列表頁(yè)?

界面測(cè)試

主要測(cè)試頁(yè)面的文字,個(gè)人信息以及查看全文按鈕是否正常顯示。

public class InterfaceTest {
    public static ChromeDriver driver;
    public static ChromeDriver getDriver(){
        if(driver == null){
            synchronized (PrepareTest.class){
                if(driver == null){
                    driver = new ChromeDriver();
                }
            }
        }
        return driver;
    }
    @BeforeAll
    public  static void start(){
        driver = getDriver();
        driver.get("http://43.143.208.132:8080/blog_system/blog-login.html");
        //使用隱式等待渲染頁(yè)面完成
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).sendKeys("zhangsan");
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).sendKeys("1234");
        driver.findElement(By.xpath("http://*[@id=\"submit\"]")).click();
    }
    @AfterAll
    public static  void close(){
        driver.quit();
    }
    /**
     * 測(cè)試個(gè)人信息
     */
    @Test
    public void testInfo(){
        String dengLu =  driver.findElement(By.xpath("/html/body/div[2]/div[1]/div/a")).getText();
        Assertions.assertEquals(dengLu,"gitee地址");
        String user = driver.findElement(By.xpath("/html/body/div[2]/div[1]/div/h3")).getText();
        Assertions.assertEquals(user,"zhangsan");
    }

    /**
     * 測(cè)試查看全文按鈕的文字
     */
    @Test
    public void testQuanWen(){
        String tiJiao =  driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[1]/a")).getText();
        Assertions.assertEquals("查看全文",tiJiao);
    }

    /**
     * 測(cè)試個(gè)人信息的頭像是否正常
     */
    @Test
    public void testUserInput(){
        WebElement webElement =  driver.findElement(By.xpath("/html/body/div[2]/div[1]/div/img"));
        Assertions.assertNotNull(webElement);
    }
    /**
     * 測(cè)試文章標(biāo)題是否正常
     */
    @Test
    public void testPasswordInput(){
        WebElement webElement =  driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[1]/div[1]"));
        Assertions.assertNotNull(webElement);
    }

}

?基于博客系統(tǒng)寫測(cè)試用例,軟件測(cè)試,junit,java,單元測(cè)試

功能測(cè)試?

查看全文按鈕的功能是否正常。

    /**
     * 查看全文按鈕是否能正確跳轉(zhuǎn)
     */
    @Test
    public void testQuanWen(){
        driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[1]/a")).click();
       String url =  driver.getCurrentUrl();
        Assertions.assertEquals("http://43.143.208.132:8080/blog_system/blog-detail.html?blogId=5",url);
        driver.navigate().back();
    }

寫博客按鈕是否正常。?

    /**
     * 寫博客超鏈接是否正常
     */
    @Test
    public void testXieBoKe(){
        driver.findElement(By.xpath("/html/body/div[1]/a[2]")).click();
        String url = driver.getCurrentUrl();
        Assertions.assertEquals("http://43.143.208.132:8080/blog_system/blog-edit.html",url);
        driver.navigate().back();
    }

基于博客系統(tǒng)寫測(cè)試用例,軟件測(cè)試,junit,java,單元測(cè)試

測(cè)試注銷超鏈接是否正常。?

/**
     * 注銷超鏈接是否正常
     */
    @Test
    public void testZhuXiao(){
        driver.findElement(By.xpath("/html/body/div[1]/a[3]")).click();
        String url = driver.getCurrentUrl();
        Assertions.assertEquals("http://43.143.208.132:8080/blog_system/blog-login.html",url);
        driver.navigate().back();
    }

基于博客系統(tǒng)寫測(cè)試用例,軟件測(cè)試,junit,java,單元測(cè)試

測(cè)試博客詳情頁(yè)?

界面測(cè)試

測(cè)試博客的詳情信息是否都正確顯示。

public class InterfaceTest {
    public static ChromeDriver driver;
    public static ChromeDriver getDriver(){
        if(driver == null){
            synchronized (PrepareTest.class){
                if(driver == null){
                    driver = new ChromeDriver();
                }
            }
        }
        return driver;
    }
    @BeforeAll
    public  static void start(){
        driver = getDriver();
        driver.get("http://43.143.208.132:8080/blog_system/blog-login.html");
        //使用隱式等待渲染頁(yè)面完成
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).sendKeys("zhangsan");
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).sendKeys("1234");
        driver.findElement(By.xpath("http://*[@id=\"submit\"]")).click();
        driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[1]/a")).click();
    }
    @AfterAll
    public static  void close(){
        driver.quit();
    }
    /**
     * 測(cè)試個(gè)人信息
     */
    @Test
    public void testInfo(){
        String dengLu =  driver.findElement(By.xpath("/html/body/div[2]/div[1]/div/a")).getText();
        Assertions.assertEquals(dengLu,"gitee地址");
        String user = driver.findElement(By.xpath("/html/body/div[2]/div[1]/div/h3")).getText();
        Assertions.assertEquals(user,"zhanger");
        WebElement webElement =  driver.findElement(By.xpath("/html/body/div[2]/div[1]/div/img"));
        Assertions.assertNotNull(webElement);
    }
    /**
     * 測(cè)試文章標(biāo)題
     */
    @Test
    public void testTitle(){
        String title =  driver.findElement(By.xpath("/html/body/div[2]/div[2]/div/h3")).getText();
        Assertions.assertNotNull(title);
    }
    /**
     * 測(cè)試文章發(fā)表日期
     */
    @Test
    public void testDate(){
        String date =  driver.findElement(By.xpath("/html/body/div[2]/div[2]/div/div[1]")).getText();
        Assertions.assertNotNull(date);
    }
    /**
     *測(cè)試文章正文
     */
    public void testText(){
        String text =  driver.findElement(By.xpath("http://*[@id=\"desc\"]/p")).getText();
        Assertions.assertNotNull(text);
    }

}

基于博客系統(tǒng)寫測(cè)試用例,軟件測(cè)試,junit,java,單元測(cè)試

功能測(cè)試

博客詳情頁(yè)的功能測(cè)試與博客列表頁(yè)相似,主要是對(duì)超鏈接進(jìn)行測(cè)試。

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class FunctionTest {
    public static ChromeDriver driver;
    public static ChromeDriver getDriver(){
        if(driver == null){
            synchronized (PrepareTest.class){
                if(driver == null){
                    driver = new ChromeDriver();
                }
            }
        }
        return driver;
    }
    @BeforeAll
    public  static void start(){
        driver = getDriver();
        driver.get("http://43.143.208.132:8080/blog_system/blog-login.html");
        //使用隱式等待渲染頁(yè)面完成
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).sendKeys("yiyi");
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).sendKeys("1234");
        driver.findElement(By.xpath("http://*[@id=\"submit\"]")).click();
        driver.findElement(By.xpath("/html/body/div[2]/div[2]/div[1]/a")).click();
    }
    @AfterAll
    public static  void close(){
        driver.quit();
    }
    /**
     * 寫博客超鏈接是否正常
     */
    @Test
    @Order(1)
    public void testXieBoKe(){
        driver.findElement(By.xpath("/html/body/div[1]/a[2]")).click();
        String url = driver.getCurrentUrl();
        Assertions.assertEquals("http://43.143.208.132:8080/blog_system/blog-edit.html",url);
        driver.navigate().back();
    }
    /**
     *測(cè)試主頁(yè)超鏈接是否正常
     */
    @Test
    @Order(2)
    public void testZguYe(){
        driver.findElement(By.xpath("/html/body/div[1]/a[1]")).click();
        String url = driver.getCurrentUrl();
        Assertions.assertEquals("http://43.143.208.132:8080/blog_system/blog-list.html",url);
        driver.navigate().back();
    }
    /**
     * 注銷超鏈接是否正常
     */
    @Test
    @Order(3)
    public void testZhuXiao(){
        driver.findElement(By.xpath("/html/body/div[1]/a[3]")).click();
        String url = driver.getCurrentUrl();
        Assertions.assertEquals("http://43.143.208.132:8080/blog_system/blog-login.html",url);
        driver.navigate().back();
    }

}

基于博客系統(tǒng)寫測(cè)試用例,軟件測(cè)試,junit,java,單元測(cè)試

博客編輯頁(yè)測(cè)試

界面測(cè)試

查看頁(yè)面的元素能否正確展示。

public class InterfaceTest {
    public static ChromeDriver driver;
    public static ChromeDriver getDriver(){
        if(driver == null){
            synchronized (PrepareTest.class){
                if(driver == null){
                    driver = new ChromeDriver();
                }
            }
        }
        return driver;
    }
    @BeforeAll
    public  static void start(){
        driver = getDriver();
        driver.get("http://43.143.208.132:8080/blog_system/blog-login.html");
        //使用隱式等待渲染頁(yè)面完成
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[1]/span[2]/input")).sendKeys("zhangsan");
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[2]/div/form/div[2]/span[2]/input")).sendKeys("1234");
        driver.findElement(By.xpath("http://*[@id=\"submit\"]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/a[2]")).click();
    }
    @AfterAll
    public static  void close(){
        driver.quit();
    }
    @Test
    public  void testEdit(){
        WebElement webElement = driver.findElement(By.xpath("http://*[@id=\"editor\"]/div[1]/div[6]"));
        Assertions.assertNotNull(webElement);
    }
    @Test
    public  void testFaBu(){
        String str = driver.findElement(By.xpath("http://*[@id=\"submit\"]")).getAttribute("value");
        Assertions.assertEquals("發(fā)布文章",str);
    }
    @Test
    public void testInputTitle(){
        WebElement webElement = driver.findElement(By.xpath("http://*[@id=\"title\"]"));
        Assertions.assertNotNull(webElement);
    }
}

基于博客系統(tǒng)寫測(cè)試用例,軟件測(cè)試,junit,java,單元測(cè)試

功能測(cè)試?

?測(cè)試能否正確發(fā)表文章。

 /**
     * 測(cè)試發(fā)表文章是否正常
     */
    @Test
    public void submit(){
        driver.findElement(By.xpath("http://*[@id=\"editor\"]/div[1]/div[6]")).sendKeys("自動(dòng)化測(cè)試的流程:");
        driver.findElement(By.xpath("http://*[@id=\"title\"]")).sendKeys("自動(dòng)化測(cè)試");
        driver.findElement(By.xpath("http://*[@id=\"submit\"]")).click();
        String url = driver.getCurrentUrl();
        Assertions.assertEquals("http://43.143.208.132:8080/blog_system/blog-list.html",url);
        driver.navigate().back();
    }

基于博客系統(tǒng)寫測(cè)試用例,軟件測(cè)試,junit,java,單元測(cè)試

標(biāo)題為空時(shí),無(wú)法發(fā)表。?

/**
     * 標(biāo)題為空無(wú)法發(fā)表
     */
    @Test
    public void submitNull(){
        driver.findElement(By.xpath("http://*[@id=\"title\"]")).clear();
        driver.findElement(By.xpath("http://*[@id=\"submit\"]")).click();
        String url = driver.getCurrentUrl();
        Assertions.assertNotEquals("http://43.143.208.132:8080/blog_system/blog-list.html",url);
        driver.navigate().back();
    }

基于博客系統(tǒng)寫測(cè)試用例,軟件測(cè)試,junit,java,單元測(cè)試文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-787380.html

到了這里,關(guān)于博客系統(tǒng)實(shí)現(xiàn)自動(dòng)化測(cè)試的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包