简体   繁体   English

如何从不断变化的字段中动态获取记录数?

[英]How can I dynamically get the number of records from a changing field?

In the bottom of tables in our application, we have a field that says, "Showing x to x of x entries", where x is the number of entries in the table.在我们应用程序的表格底部,我们有一个字段,上面写着“显示 x 到 x 个条目中的 x”,其中 x 是表格中的条目数。

I am trying to create a function that can save the last 'x' value in the above string to compare it to a new value after a record is deleted.我正在尝试创建一个函数,该函数可以保存上述字符串中的最后一个 'x' 值,以便在删除记录后将其与新值进行比较。

For instance...例如...

  • The text is, 'Showing items 1 - 100 of 100'文本是,“显示项目 1 - 100 of 100”
  • (I want to store the last 100 number as x for assertion) (我想将最后 100 个数字存储为 x 以进行断言)
  • Delete 1 record删除 1 条记录
  • The text is, 'Showing items 1 - 99 of 99'文本是,“显示第 1 - 99 项,共 99 项”
  • (I want to store the last 99 number as y for assertion) (我想将最后 99 个数字存储为 y 以进行断言)

Is there any straight forward way to store these values with C# or Selenium?有什么直接的方法可以用 C# 或 Selenium 存储这些值吗? The problem is that when the test is run, the x and y values above will consistently be different because of other tests that run previously.问题是当测试运行时,由于之前运行的其他测试,上面的 x 和 y 值将始终不同。 I know that long term I should have consistent data for tests but right now that is a problem for later.我知道从长远来看,我应该有一致的测试数据,但现在这是以后的问题。

The simplest storage is local variables, nice and clean and contained:最简单的存储是局部变量,干净整洁,包含:

[TestFixture]
public class MyTests {
  [Test]
  public void YourTest() {
    var number = 0;

    number = myPageObjectModel.GetResultCount();

    myPageObjectModel.Delete();

    Assert.AreEqual(number - 1, myPageObjectModel.GetResultCount());
  }
}

You could store the number on the class and it would be more widely available, but I feel this would start coupling your tests as they would have to run in a specific order, so I'd recommend starting with a local variable if you can.您可以将数字存储在类中,它会更广泛地可用,但我觉得这会开始耦合您的测试,因为它们必须按特定顺序运行,因此如果可以,我建议从局部变量开始。

If you are using a technology that forces you to skip between methods in different classes (like SpecFlow) it is better to preserve state between steps in a scenario context class.如果您使用的技术迫使您在不同类(如 SpecFlow)中的方法之间跳过,最好在场景上下文类中的步骤之间保留状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM