I have created a method which is as follows:
@Test(priority = 61)
public void Schedule_Valid_Promocode_Discount () throws InterruptedException
{
WebElement Discount = driver.findElement(By.xpath("html/body/max-app-root/max-schedule/div/div[2]/max-campaign-information/div/aside/div[2]/div[3]/div/div[3]/div[2]/h4"));
Assert.assertTrue(Discount!=null); // Check if discount appeared
Assert.assertEquals("RM 1,000", Discount.getText());
}
public WebElement getSchedule_Discount_Amount () throws InterruptedException
{
WebElement Discount = driver.findElement(By.xpath("html/body/max-app-root/max-schedule/div/div[2]/max-campaign-information/div/aside/div[2]/div[3]/div/div[3]/div[2]/h4"));
return Discount;
}
I'm trying to store this value so that I can test the same value in upcoming test case. The test case is as follows:
@Test(priority = 79)
public void BillingDetail_InvoiceTab_DiscountAmount () throws InterruptedException
{
//Check Discount amount on billing detail page
WebElement InvoiceDiscount = driver.findElement(By.xpath("html/body/max-app-root/max-summary/div/div/div[2]/div/div/mat-card/mat-card-content/div[1]/div[1]/div/p[2]/span"));
WebElement Discount = this.getSchedule_Discount_Amount();
Assert.assertEquals(Discount.getText(), InvoiceDiscount.getText());
}
When I try to call this.getSchedule_Discount_Amount();
I get error - unable to locate element.
I have only one class and all my test cases falls under same class. I'm new to automation testing and not sure in what scenerios a new class should be created.
@Test (priority = 61)
it successfully finds the element. But when it comes to@Test (priority =72)
, it is still trying to find the element which I'm returning in test case 61. Surely that element is no more available during test case 72 because now we are on a different page. I want it to store the value in test 61 and validate value of test 72 with 61. – Sanchit Jun 22 '18 at 7:30