1

I am using Playwright with C# and Xunit, but I think Selenium and Xunit users can help as well. I need to get the value of an element in one test and pass this value to another test. For example,

[Fact]
public async Task GetData()
{
   var data = await Page.GetAttribute(selector1, "value");
}
[Fact]
public async Task PassData()
{
   await Page.FillAsync(selector2, data); 
}

This is a simple example, the real-life test has a lot of steps, so I want to break one big into several small tests.

Valerie
  • 11
  • 1
  • I think you're using the wrong tool for the job. Have a look at [SpecFlow](https://specflow.org/) which will allow you to break up your test into multiple parts and has better support for UI automation testing – Hayden Aug 09 '21 at 22:16
  • 4
    "Test in isolation" - tests should be isolated from other tests. Instead of passing data between tests, call same method in another test to get the data. Notice that XUnit will instantiate new instance of the test class for every test method. – Fabio Aug 10 '21 at 07:06
  • Thank you, Fabio. This is what I do right now. There are many steps to get that data, and I need to use it further in multiple tests, so I am looking for a workaround for this particular TC. Probably, will have to get that data from DB to avoid repeating those steps in several tests. – Valerie Aug 10 '21 at 13:50
  • Wrap all steps within single method or use class or collection fixtures to run multiple tests based on the same configured scenario – Fabio Aug 16 '21 at 05:36

0 Answers0