2014-09-19 18 views
-1

.......所以,我有我創建的以下類作爲我的自動化測試包的一部分,但我我對'ListPostsPage.GoTo(PostType.Page)'代碼行收到錯誤,建議:'名稱PostType在當前上下文中不存在'。這個類的代碼如下:任何人都可以協助「名稱'posttype'在當前上下文中不存在」錯誤

using Microsoft.VisualStudio.TestTools.UnitTesting; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace WordpressTests 
{ 
    [TestClass] 
    public class PageTests 
{ 
    [TestInitialize] 
    public void Init() 
    { 
     Driver.Initialise(); 
    } 

    [TestMethod] 
    public void CanEditAPage() 
    { 
     LoginPage.GoTo(); 
     LoginPage.LoginAs("XXXXXX").WithPassword("XXXXXX").Login(); 

     **ListPostsPage.GoTo(PostType.Page);** 
     ListPostsPage.SelectPost("Sample Page"); 

     Assert.IsTrue(NewPostPage.IsInEditMode(), "Wasn't in edit mode"); 
     Assert.AreEqual("Sample Page", NewPostPage.Title, "Title did not match"); 
    } 

    [TestCleanup] 
    public void Cleanup() 
    { 
     Driver.Close(); 
    } 
    } 
} 

僅供參考,對於ListPostsPage類的代碼如下:

using OpenQA.Selenium; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace WordpressTests 
{ 
    public class ListPostsPage 
{ 
    public static void GoTo(PostType postType) 
    { 
     switch (postType) 
     { 
      case PostType.Page: 
       Driver.Instance.FindElement(By.Id("menu-pages")).Click(); 
       Driver.Instance.FindElement(By.LinkText("All Pages")).Click(); 
       break; 
     } 
    } 

    public static void SelectPost(string title) 
    { 
     var postLink = Driver.Instance.FindElement(By.LinkText("Sample Page")); 
     postLink.Click(); 
    } 

    public enum PostType 
    { 
     Page 
    } 

    } 
} 

沒有人有任何想法什麼問題可能是什麼?請記住我對此很新,所以請好好的! :-)

任何幫助將不勝感激。

乾杯

安迪

+0

正如我想指出你從執行使用Selenium的頁面對象模型大大受益點。在你的代碼中一切都是靜態的! – Arran 2014-09-20 08:27:41

回答

1

PostTypeListPostsPage枚舉成員,但你要訪問它,彷彿它是一個靜態類。

你應該這樣做:

ListPostsPage.GoTo(ListPostsPage.PostType.Page); 
相關問題