webdriver自動化測試初試

之前已經(jīng)搭建了測試需要的環(huán)境,也學習了locate elements的方法,下面我們就來創(chuàng)建第一個簡單的自動化測試用例。

創(chuàng)新互聯(lián)致力于互聯(lián)網(wǎng)網(wǎng)站建設與網(wǎng)站營銷,提供網(wǎng)站設計制作、網(wǎng)站建設、網(wǎng)站開發(fā)、seo優(yōu)化、網(wǎng)站排名、互聯(lián)網(wǎng)營銷、小程序定制開發(fā)、公眾號商城、等建站開發(fā),創(chuàng)新互聯(lián)網(wǎng)站建設策劃專家,為不同類型的客戶提供良好的互聯(lián)網(wǎng)應用定制解決方案,幫助客戶在新的全球化互聯(lián)網(wǎng)環(huán)境中保持優(yōu)勢。

測試場景如下:

1.打開百度首頁

2.在搜索框輸入關鍵字搜索,比如:webdriver automation testing

3.點擊百度一下button

4.驗證搜索結果是否包含輸入的關鍵字

用例自動化測試代碼實例如下:

package com.example.tests;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.Assert;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;

public class BaiDuSearchTest {

private WebDriver driver;

private String baseUrl;

@BeforeMethod

        public void setUp() throws Exception {

    //Launch Firefox browser

   driver = new FirefoxDriver();

   baseUrl = "http://www.baidu.com";

 }

 @Test

        public void baiDuSearchTest() throws Exception {

    String exResult="WebDriver automation testing";

    //Open 百度  home page

   driver.get(baseUrl);

   //Locate search box and input search keyword

   driver.findElement(By.id("kw1")).sendKeys("WebDriver automation testing");

   //Click 百度一下 button

   driver.findElement(By.id("su1")).click();

   //在結果頁面找到第一個link并驗證搜索關鍵字顯示在鏈接中

   String actResult=driver.findElement(By.id("1")).getText();

   Assert.assertTrue(actResult.contains(exResult));

   

 }

 @AfterMethod

public void tearDown() throws Exception {

   driver.quit();

 }

}

然后直接右擊該java文件選擇run as TestNG test,然后可以查看自動化測試用例的執(zhí)行了。

最簡單的一個測試用例就到這里了。是不是很easy?

網(wǎng)頁題目:webdriver自動化測試初試
文章轉(zhuǎn)載:http://www.muchs.cn/article38/ippisp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、網(wǎng)站維護、移動網(wǎng)站建設、全網(wǎng)營銷推廣、軟件開發(fā)、手機網(wǎng)站建設

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作