How many types of xpath are there?

 In Selenium, there are mainly two types of XPath used for locating elements: 1. Absolute XPath: This XPath starts from the root node and follows the complete path to the element. It is highly specific and is dependent on the structure of the HTML document. Example: /html/body/div[1]/div[2]/div[1]/span 2. Relative XPath: This XPath starts from any element in the HTML document (not necessarily from the root). It is more flexible and commonly used because it is less likely to break if the structure of the page changes slightly. Example: //div[@class='example'] Additionally, XPath can be classified by the type of syntax used for selecting elements: Attribute-based XPath: Selects elements based on their attributes (e.g., id, class, name, etc.). Example: //input[@name='username'] Text-based XPath: Selects elements based on their text content. Example: //button[text()='Submit'] Contains() function: Allows partial matching of attributes or text. Example: //a[contains(@...

IRetryAnalyzer

 IRetryAnalyzer:- 

  • IRetryAnalyzer is an interface in TestNG that allows you to programmatically retry failed tests during        the same test execution.
  • You implement the retry() method to specify the conditions for retrying a test.
  • Use IRetryAnalyzer to handle transient failures dynamically.
  • Run testng-failed.xml as a follow-up to catch any persistent issues.
  • Which One to Use?

    ScenarioRecommendation
    Large test suiteRun testng-failed.xml
    Debugging failed tests after runRun testng-failed.xml
    Handling flaky tests automatically      Use IRetryAnalyzer
    Continuous Integration (CI) setupUse IRetryAnalyzer



    //ClassA

    package TestNG;


    import java.util.List;


    import org.openqa.selenium.By;

    import org.openqa.selenium.WebDriver;

    import org.openqa.selenium.WebElement;

    import org.openqa.selenium.chrome.ChromeDriver;

    import org.testng.Assert;

    import org.testng.annotations.Test;


    public class ClassA {


    @Test

    public void testCase1() {


    System.out.println("This is test case1");

    Assert.assertTrue(false);

    }



    @Test

    public void testCase2() {


    System.out.println("This is test case2");

    Assert.assertTrue(true);


    }


    }

    //classB


    package TestNG; import org.testng.Assert; import org.testng.annotations.Test; public class ClassB { @Test public void testCase3() { System.out.println("This is test case3"); Assert.assertTrue(true); } @Test public void testCase4() { System.out.println("This is test case4"); Assert.assertTrue(true); } }


    //ClassC

    package TestNG; import java.util.ArrayList; import java.util.List; import org.testng.TestNG; import org.testng.annotations.AfterTest; public class ClassC { @AfterTest public void runFailedTestCases() { TestNG object = new TestNG(); List <String> list = new ArrayList<String>(); list.add("D:\\TableAutomation\\test-output\\Suite\\testng-failed.xml"); object.setTestSuites(list); object.run(); } }

    Comments

    Popular posts from this blog

    Sample Questions for ISTQB (SET-2)

    What is the default package in Java if no package is specified?