Since you need to access a value from one test in another test, and the two tests are run in different test runs, you will need to save the URL to a text file. When the second test runs, open that text file, read the URL and use it.
Test #1
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
button.Click();
wait.Until(ExpectedConditions.StalenessOf(button));
File.WriteAllText(@"pathourl.txt", driver.Url);
Note: driver.Url
is already a string. No need to call driver.Url.ToString()
.
Test #2 (run some number of days later)
var urlFromPreviousTest = File.ReadAllText(@"pathourl.txt");
driver.Navigate().GoToUrl(urlFromPreviousTest);
Since you have two separate invocations of tests, you need some sort of persistent storage. Saving the URL to a file or database is your only option here. No in-memory solutions will work, because the existing memory allocated for a test is discarded once the test runner closes down.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…