每次失败都会在量具报告中获取失败的断言列表

时间:2019-02-11 21:32:15

标签: c# selenium nunit getgauge

我正在使用Thoughtworks的Gauge自动执行UI测试。 每次断言在我的测试中失败时,都会列出断言中指示的消息。

例如,在场景1中此代码失败时

Assert.True(listsMatch, "There are differences between the Test Dropdown List on the Report Template Editor page and the reference list");

此消息转到方案1报告中的“量具自动化”报告

There are differences between the Test Dropdown List on the Report Template Editor page and the reference list

  Expected: True

  But was:  False

当下一个断言失败(在下一个场景中)时,问题就来了,前一个断言失败的所有消息都被列出了(针对两个失败的场景),而不是仅仅列出了新的消息(针对第二个失败的场景) )。 例如,输出看起来像这样,先前来自方案1的失败的断言消息在下面列出为“ 2)”,而来自方案2的当前失败的断言消息在下面列出为“ 1)”

Multiple failures or warnings in test:

  1)   The OK button was not visible to click on after 6 seconds

  Expected: True

  But was:  False



  2)   There are differences between the Test Dropdown List on the Report Template Editor page and the reference list

  Expected: True

  But was:  False

如何仅将新的断言消息输出到报告?有办法吗?

我没有看到任何可能的解决方案

我期望的是,对于任何给定的断言,仅与该断言相关的消息将被输出到仪表自动化报告中,而不是在所有运行的测试中都列出所有失败。

我想到的另一个细节是断言处于不同的场景中。

请求的代码示例(请注意,这是示例代码,用于说明Asserts的分布式性质。我认为在编写示例时遇到了大多数次要问题,但是如果我错过了定义变量或某些次要问题的话,请意识到这一点只是一个例子,不是我运行的实际代码): '''c#

class Steps_Button_OK
{
    [Step("Click the OK button")]
    public void Click()
    {
        double waitCount = 0;
        int maxWait = 5;
        int waitInterval = 1;
        int numOfElements = 0;

        // This for loop is made to poll to see if the elements have loaded yet.
        do
        {
            numOfElements = ButtonWebElementList.Count;
            if (numOfElements > 0)
            {
                break;
            }
            else
            {
                waitCount += waitInterval;
                DriverExtensions.WaitXSeconds(waitInterval);
            }
        } while (numOfElements <= 0 && waitCount < maxWait);

        if (waitCount >= maxWait)
        {
            GaugeMessages.WriteMessage("The {0} button was NOT found under the maximum wait time of {1} seconds.", this.ButtonDescriptor, maxWait);
            screenshotsteps.TakeFullScreenshotAndWriteStep("Exception");
            Assert.True(false);
        }
        if (logging)
        {
            GaugeMessages.WriteMessage("The {0} button was found at {1} seconds.", this.ButtonDescriptor, waitCount);
        }
        ButtonWebElement.Click();
    }
}


class Steps_Test_Dropdown
{
    [Step("Verify Lists Match")]
    public void OptionsMatchListInScenStore()
    {
        PO_BasePageObject_SelectDropdown _selectDropdownElement = new PO_BasePageObject_SelectDropdown();
        string scenarioStoreVariable = "OldList"; 
        int maxWait = 5; 
        double waitInterval = 1;
        bool listsMatch = true;
        IList<string> oldStringList = (IList<string>)scenarioStore.Get(scenarioStoreVariable);
        _selectDropdownElement.Options_WaitToExist(maxWait, waitInterval);
        IList<string> dropdownTextList = _selectDropdownElement.Options_ValidList();

        int oldLength = oldStringList.Count;
        int drpdwnLength = dropdownTextList.Count;

        // Make sure all of the dropdown text values are in the reference (old) String list
        foreach (string feString in dropdownTextList)
        {
            if (!oldStringList.Contains(feString))
            {
                listsMatch = false;
                GaugeMessages.WriteMessage("- The value {0} is in the {1} dropdown list but not in the reference list", feString, _selectDropdownElement.SelectDescriptor);
            }
        }

        // Make sure all of the reference (old) list text values are in the Test dropdown list
        foreach (string feString in oldStringList)
        {
            if (!dropdownTextList.Contains(feString))
            {
                listsMatch = false;
                GaugeMessages.WriteMessage("- The value {0} is in the reference list but not in the {1} dropdown list", feString, _selectDropdownElement.SelectDescriptor);
            }
        }

        GaugeMessages.WriteMessage("There are {0} tests listed in the {1} Dropdown", drpdwnLength, _selectDropdownElement.SelectDescriptor);
        GaugeMessages.WriteMessage("There are {0} tests listed in the reference list", oldLength);

        // Assert to check that the lists match (or don't) 

        Assert.True(listsMatch, "There are differences between the {0} Dropdown List and the reference list", _selectDropdownElement.SelectDescriptor);
    }
}

'''

0 个答案:

没有答案