簡體   English   中英

如何使用PageObject模型在C#中初始化完整的類?

[英]How do I initialize a complete class in C# with the PageObject model?

因為C#中不推薦使用pageFactory。 我想知道如何在C#上初始化類。 我試圖通過@Findby調用它們,然后在@Findby調用它們,但是我不想編寫10thousend對象。

Pagafactory.Init = Deprecated

我如何初始化我的WebObject所在的Page對象

PageObject存儲庫示例:

     public class LoginPage {

        private IWebDriver driver;

        public IWebElement LP_Accountfld => driver.FindElement(By.CssSelector("#i0116"));

測試用例:

public void Login (){ //LogIn TestCase

            driver.Navigate().GoToUrl(Variables.URL);
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); 
            var Creator = new CreatorModel();
Creator.LP_Accountbtn.Click();

當我運行代碼時,變量為

處理對象的正確方法是不使用[FindsBy ...]創建對象,而是像這樣更平滑,更干凈地創建東西:

public IWebElement  LP_Accountbtn => _driver.FindElement(By.CssSelector("#contentLogin > div:nth-child(1) > form:nth-child(1) > div:nth-child(2) > button:nth-child(1)"));

您稱之為:

var Creator = new CreatorModel();
Creator.LP_Accountbtn.Click();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM