Why do my tests fail when run together, but pass individually?

前端 未结 7 1132
有刺的猬
有刺的猬 2020-12-29 23:56

When I write a test in Visual Studio, I check that it works by saving, building and then running the test it in Nunit (right click on the test then run).

The test wo

相关标签:
7条回答
  • 2020-12-30 00:31

    I think you need to ensure, that you can log on for the second test, this might fail, because you are logged on already?

    -> putting the logon in a set up method or (because it seems you are using the same user for both tests) even up to the fixture setup -> the logoff (if needed) might be put in the tear down method

         [SetUp]
         public void LaunchTest()
         {
            NavigateTo<LogonPage>().LogonAsCustomerAdministrator();
         }
    
         [TearDown]
         public void StopTest()
         {
            // logoff
         }
         [Test]
         public void Test1()
         {...}
         [Test]
         public void Test2()
         {...}
    

    If there are delays in the DOM instead of a thread.sleep I recommend to use webdriver.wait in combination with conditions. The sleep might work in 80% and in others not. The wait polls until a timeout is reached which is more reliable and also readable. Here an example how I usually approach this:

        var webDriverWait = new WebDriverWait(webDriver, ..);
        webDriverWait.Until(d => d.FindElement(By.CssSelector(".."))
            .Displayed))
    
    0 讨论(0)
提交回复
热议问题