0

我正在使用 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

如何仅将新的断言消息输出到报告中?有没有办法做到这一点?

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

我期望的是,对于任何给定的断言,只有与该断言相关的消息将被输出到 Gauge Automation 报告,而不是在所有运行的测试中列出每个失败的列表。

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

请求的代码示例(请注意,这是说明断言的分布式性质的示例代码。我认为我在制作示例时发现了大多数小问题,但如果我错过了定义变量或其他小问题,请意识到这只是一个例如,不是我运行的实际代码):'''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);
    }
}

'''

4

0 回答 0