How to assert after canceling unsaved changes current page stays where it was?
Introduction
I don't think this is the best way to do the assertion... however, I currently have no idea of other options. Welcome any comments. Thanks in advance.
Tasks
Today, I tested canceling unsaved changes function for new invoice creation.
I designed two test scenarios for this cancelling.
[ ] 1. If no changes are made, click on Cancel button--->Go back to the previous page.
[ ] 2. If changes are made, click on the Cancel button--->a model including 'Yes' and 'No' buttons pop up:
--->yes, modal is closed, and changes are not saved, and go back to the previous page;
---->no, modal is closed, and changes are not saved, and stay where it was.
Task1 and Yes in Task2 are similar. I only need to verify a button is available on the previous page. But I really have no idea about find elements to verify the current page didn't change. I actually thought I should verify all the element on this page, but I don't know how to read the text value that I input into the field....so seems a lot is going on.
So I am going to talk about how to assert current page stays where it was in task2. (Maybe someday I can get to know another way.)
The solution is to use this bit.
IWebDriver driver = new Chromedriver();
String currentURL = driver.Url;
So this part of the code is:
//Go to invoice creation page. Do some changes, then click on the cancel button -> click no button.
driver.FindElements(By.XPath("//*[@class='btn btn-lg btn-success']"))[0].Click();
Thread.Sleep(2000);
driver.FindElement(By.XPath("//*[@name='clientname']")).Clear();
driver.FindElement(By.XPath("//*[@name='clientname']")).SendKeys("abc");
Thread.Sleep(2000);
string url_0 = driver.Url; //Get URL before modal pops up
driver.FindElements(By.XPath("//*[@class='btn btn-secondary']"))[0].Click();
Thread.Sleep(5000);
//click on no, then stay where it was.
driver.FindElement(By.XPath("//*[@class='btn btn-primary']")).Click();
Assert.AreEqual(url_0, driver.Url); //Get current URL
//Thread.Sleep(1000);
How to assert after canceling unsaved changes current page stays where it was?
Introduction
I don't think this is the best way to do the assertion... however, I currently have no idea of other options. Welcome any comments. Thanks in advance.
Tasks
Today, I tested canceling unsaved changes function for new invoice creation. I designed two test scenarios for this cancelling.
[ ] 1. If no changes are made, click on Cancel button--->Go back to the previous page.
[ ] 2. If changes are made, click on the Cancel button--->a model including 'Yes' and 'No' buttons pop up: --->yes, modal is closed, and changes are not saved, and go back to the previous page; ---->no, modal is closed, and changes are not saved, and stay where it was.
Task1 and Yes in Task2 are similar. I only need to verify a button is available on the previous page. But I really have no idea about find elements to verify the current page didn't change. I actually thought I should verify all the element on this page, but I don't know how to read the text value that I input into the field....so seems a lot is going on. So I am going to talk about how to assert current page stays where it was in task2. (Maybe someday I can get to know another way.)
The solution is to use this bit.
So this part of the code is:
Thanks and comments.