[ ] 3. Do the assertion by comparing the actual value to the expected value in each cell.
1. Locate the table element
Find out the table tag and the relevant attributes for it from this bit of code.
<table _ngcontent-c8="" class="table table-bordered table-striped table-hover table-light" matsort="" matsortactive="dateCreated" matsortdirection="desc" matsortdisableclear="" matsortstart="desc">
To locate the table element I have to get the table ID, name or class, here I have
table class name which is "table table-bordered table-striped table-hover table-light" using XPath.
driver.FindElement(By.XPath("//*[@class='table table-bordered table-striped table-hover table-light']"));
To locate row1, column1, we only need to add /tbody/tr[1]/td[1] after the table locator.
With the same idea, if I want to get row1 column6, I would add /tbody/tr[1]/td[6]
Simple as it is, isn't it!!!
3. Do the assertion
Assert.AreEqual(expected_value, actual_valaue);
Here are the codes for this test:
//verify the ivoice is the new-added one
string invoice_number_value = driver.FindElement(By.XPath("//*[@class='table table-bordered table-striped table-hover table-light']/tbody/tr[1]/td[1]")).Text;
Assert.AreEqual(invoice_number, invoice_number_value);
//Get invoice creation date
string invoice_creation_date = driver.FindElement(By.XPath("//*[@class='table table-bordered table-striped table-hover table-light']/tbody/tr[1]/td[2]")).Text;
Assert.AreEqual(currentdate, invoice_creation_date);
//Get invoice client on the list
string invoice_client = driver.FindElement(By.XPath("//*[@class='table table-bordered table-striped table-hover table-light']/tbody/tr[1]/td[3]")).Text;
Assert.AreEqual(clientname, invoice_client);
//Get invoice amount on the list
string invoice_total_amount = driver.FindElement(By.XPath("//*[@class='table table-bordered table-striped table-hover table-light']/tbody/tr[1]/td[4]")).Text;
string newtotal1_format = "$" + newtotal1;
Assert.AreEqual(newtotal1_format, invoice_total_amount);
//Get omvoice due date on the list
//string list_duedate = driver.FindElement(By.XPath("//*[@class='table table-bordered table-striped table-hover table-light']/tbody/tr[1]/td[5]")).Text;
//Assert.AreEqual(duedate, list_duedate);
//Get invoice status on the list
string list_invoice_status = driver.FindElement(By.XPath("//*[@class='table table-bordered table-striped table-hover table-light']/tbody/tr[1]/td[6]")).Text;
Assert.AreEqual("Draft", list_invoice_status);
Thread.Sleep(2000);
Introduction
This is the table to be tested:
HTML code for it:
Tasks
I want to test the first row in the table is the one that I have added. so I need to:
1. Locate the table element
Find out the table tag and the relevant attributes for it from this bit of code.
<table _ngcontent-c8="" class="table table-bordered table-striped table-hover table-light" matsort="" matsortactive="dateCreated" matsortdirection="desc" matsortdisableclear="" matsortstart="desc">
To locate the table element I have to get the table ID, name or class, here I have table class name which is "table table-bordered table-striped table-hover table-light" using XPath.
driver.FindElement(By.XPath("//*[@class='table table-bordered table-striped table-hover table-light']"));
2. Locate row 1, column 1, row 1 column 2... and row 1 column 6
To locate row1, column1, we only need to add
/tbody/tr[1]/td[1]
after the table locator. With the same idea, if I want to get row1 column6, I would add/tbody/tr[1]/td[6]
Simple as it is, isn't it!!!3. Do the assertion
Assert.AreEqual(expected_value, actual_valaue);
Here are the codes for this test:
Thanks and comments.