Selenium: Check i the testcase pass or fail

元气小坏坏 提交于 2020-01-17 05:37:09

问题


Guys First of all I am totally new for Selenium. I am having a automation project. In my project, I am creating a screenshot function to take screenshots of my event which I have created for my testcases. Now if my test cases passes then all screenshot should move to Pass folder, else fail folder.

I would like to know how to detect that my test case pass?

I know Nunit detects but I wanted to program it so that I cam place my screenshot as well as log file to pass or fail folder.

Program in C# Selenium Nunit to run my test case.


回答1:


I think you meant was this. But there is work around for this. You need to add your code accordingly.

 if (TestContext.CurrentContext.Result.Outcome.Equals(ResultState.Failure))
    {
        IntegrationTest.WriteInLog("FAILS");
    }
 else if (TestContext.CurrentContext.Result.Outcome.Equals(ResultState.Success))
    {
        IntegrationTest.WriteInLog("SUCESS");
    }



回答2:


Check status property and compare it with TestStatus enum at teardown method.

NUnit2:

TestContext.CurrentContext.Result.Status

NUnit3:

TestContext.CurrentContext.Result.Outcome.Status



来源:https://stackoverflow.com/questions/35230418/selenium-check-i-the-testcase-pass-or-fail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!