qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請訪問 http://qaseven.github.io/

          解決TestNG測試用例依賴性的問題

          如果測試用例間有依賴性,也就是如果想執(zhí)行B,就必須要先執(zhí)行A。那么用例的執(zhí)行順序就很關(guān)鍵,如何來指定用例的順序呢,有這樣幾種方法:

            1. 給用例加編號:

          public void test01Login(){
          XXX
          }
          public void test02Add(){
          XXX
          }
          public void test03Delete(){
          XXX
          }

            2. 加上關(guān)鍵字

            硬依賴的例子:

          @Test
          public void serverStartedOk() {}
          @Test(dependsOnMethods = { "serverStartedOk" })
          public void method1() {}

            此例中,method1() 依賴于方法 serverStartedOk(),從而保證

            serverStartedOk() 總是先運行。

          public class Demo1 {
           WebDriver driver;
           
           @BeforeClass
           public void beforeClass() {
            System.setProperty("webdriver.ie.driver","E:\\WebDriver\\IEDriverServer.exe");
            driver = new InternetExplorerDriver();
           }
           //登錄博客
           @Test
           public void login() throws InterruptedException {
            System.out.println("login開始執(zhí)行了");
            driver.get(http://blog.ifeng.com);
            driver.findElement(By.id("username")).sendKeys("itest20");
            driver.findElement(By.id("password")).sendKeys("123456");
            driver.findElement(By.xpath("http://input[@value='登錄']")).click();
            driver.navigate().refresh();
           }
           //驗證標題是否為空
           @Test(dependsOnMethods = { "login" })
           public void noSubject() throws InterruptedException{
            System.out.println("noSubject開始執(zhí)行了");
            driver.get(http://blog.ifeng.com);
            String originalHandle = driver.getWindowHandle();
            driver.findElement(By.linkText("發(fā)表博文")).click();
            for(String winHandle: driver.getWindowHandles()){
             if(winHandle!=originalHandle)
              driver.switchTo().window(winHandle);
             driver.manage().window().maximize();
            }
            Thread.sleep(2000);
            Assert.assertTrue(FindElement.isElementExist(driver, By.id("saveArticle")));
            driver.findElement(By.id("saveArticle")).click();
            //判斷當(dāng)標題為空時提示是否正確
            boolean expected = true;
            boolean actual = (driver.findElement(By.id("blog_tishi")).getText()).endsWith("請?zhí)顚?a href="" target="_self" style="word-break: break-all; color: #202859; text-decoration: none;">文章標題");
            Assert.assertEquals(actual, expected, "標題為空");
            Thread.sleep(3000);
           }
           //驗證內(nèi)容是否為空
           @Test(dependsOnMethods = { "noSubject" })
           public void noContent() throws InterruptedException{
            System.out.println("noContent開始執(zhí)行了");

          posted on 2013-08-14 10:25 順其自然EVO 閱讀(271) 評論(0)  編輯  收藏 所屬分類: selenium and watir webdrivers 自動化測試學(xué)習(xí)

          <2013年8月>
          28293031123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 乐安县| 论坛| 恭城| 金平| 太康县| 凌海市| 加查县| 凌源市| 茌平县| 聂荣县| 蒲城县| 南华县| 雅江县| 凤山市| 镇安县| 黔江区| 嵊州市| 宜城市| 古田县| 海安县| 正宁县| 福安市| 囊谦县| 隆回县| 共和县| 南康市| 富平县| 和龙市| 大竹县| 北宁市| 金乡县| 台州市| 许昌县| 遂宁市| 瓦房店市| 聂拉木县| 台湾省| 丹阳市| 巴塘县| 封开县| 天峨县|