在方法中添加了try and catch函数,并为[DataRow]或[DynamicData]获取了异常?

好吧,我有一种方法使用硒和c#登录到网站,名为LoginAndSelectAutomationFleet,但是当我运行它时,我得到了一个例外:

microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel.TestFailedException: Only data driven test methods can have parameters. Did you intend to use [DataRow] or [DynamicData]?

我所做的就是通过try and catch将方法转换为测试方法。这是代码:

[TestMethod]
 public void LoginAndSelectAutomationFleet(IWebDriver driver)
        {
            // login the user
            _userSetRepo = new UserSetttingsRep(driver);
            _regRep = new UserRegRep(driver);
            objCommon = new clsCommon(driver);
            objCommon.loginVT(driver);
            string getTitle = driver.Title;
            try
            {
                Assert.IsTrue(getTitle == "Amazing Power");
                Console.WriteLine("The application " + getTitle + " has logged in successfully!");


            }
            catch(Exception ex)
            {
                Assert.Fail(ex.Message);
                Console.WriteLine("The user failed to log in successfully!");
            }
            System.Threading.Thread.Sleep(3000);
            WebDriverWait wait = new WebDriverWait(driver,TimeSpan.FromSeconds(60));
            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeclickable(By.XPath("//span[text()='User']"))).Click(); 


            WebDriverWait wait1 = new WebDriverWait(driver,TimeSpan.FromSeconds(60));
            wait1.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//a[@class='vt-navbar__child-menu-link']//input")));

            objCommon.SendKeysAndClickTab(_userSetRepo.inputOrgansiation,"Companyxyz",driver);
}

如何解决?

mufcoshea 回答:在方法中添加了try and catch函数,并为[DataRow]或[DynamicData]获取了异常?

一种测试方法必须满足以下要求:

  • 以[TestMethod]属性装饰。

  • 它返回void。

  • 它不能有参数。

As per documentation.

您最好的解决方案是从IWebDriver driver内调用的方法中获取[TestMethod]或将IWebDriver driver作为全局变量。例如:

[TestMethod]
 public void LoginAndSelectAutomationFleet()
 {
     IWebDriver driver = someMethod() //Returns an IWebDriver that you need.
 }
本文链接:https://www.f2er.com/3165891.html

大家都在问