qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

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

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

            1. 給用例加編號:

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

            2. 加上關鍵字

            硬依賴的例子:

          @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開始執行了");
            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開始執行了");
            driver.get(http://blog.ifeng.com);
            String originalHandle = driver.getWindowHandle();
            driver.findElement(By.linkText("發表博文")).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();
            //判斷當標題為空時提示是否正確
            boolean expected = true;
            boolean actual = (driver.findElement(By.id("blog_tishi")).getText()).endsWith("請填寫文章標題");
            Assert.assertEquals(actual, expected, "標題為空");
            Thread.sleep(3000);
           }
           //驗證內容是否為空
           @Test(dependsOnMethods = { "noSubject" })
           public void noContent() throws InterruptedException{
            System.out.println("noContent開始執行了");

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

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

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 兴安盟| 南昌市| 福贡县| 邹平县| 偏关县| 海林市| 龙井市| 榆树市| 通海县| 公主岭市| 水城县| 石台县| 大名县| 永定县| 洛川县| 安福县| 白银市| 卢龙县| 奈曼旗| 南漳县| 漯河市| 北碚区| 夏河县| 台南市| 奈曼旗| 上虞市| 尤溪县| 萝北县| 调兵山市| 虹口区| 宣武区| 山西省| 类乌齐县| 伊吾县| 炉霍县| 霍州市| 淮滨县| 图们市| 泌阳县| 奇台县| 滁州市|