Selenium Framework Interview Questions

By | January 24, 2019

TestNG and FrameWork


  1. What is a framework??
    A framework is basically set of rules or Guidelines set to perform task efficiently and effectively.
    There are no thumb rule that the framework should be in particluar way. It will depend on the task/application to which
    we are going to design a framework.
  2. What are the advantages of framework?
    Having framework is one of the best standard. It will have following benefits:

      Tasks and code will be in organized manner.
      Eliminating redundant work, reusability of code.
      Maintenance will become easier and tractable.
      Much efficient than developing without a framework.
      Reporting will become easier and better.
  3. What are different types of Frameworks in automation. Explain each of it?
      Data Driven Testing Framework:
      The data-driven testing approach is a widely used methodology in software test automation.
      We can use the same test script to check different test conditions by passing set of data to
      the test script. Test cases will receive the data from the external files (Database or Excel) and store them into variables.
      During execution scripts will get executed with this data.
      Keyword Driven Testing Framework:
      In KDT tests can be created and executed using keywords. Keywords can be given to actions, objects or can be roles.
      It will depend on the Application Under Test(AUT).
      Hybrid Testing Framework:
      This can be combination of any approach. As I mentioned there is no thumbrule. Depending on AUT
      any of the Framework can be combined.
      Behavioural Driven Framework:
      In Behavior Driven Development(BDD) framework test cases will be written in simple langugage(Gherkin), so that developers testers and anyone can understand scenario easily.
      Module dependant framework:
      In this framework framework will consists of classes module wise. Each module scripts will be developed individually. Combining all will test AUT.

    Apart from this there Page Factory Framework which is already provided in selenium/TestNG. One can enhance that and utilize accordingly.

  4. What are tools used in framework used in each stage from end to end?
    An example can be:

      Approach of framework: Page Object Model. Created seperate classes for each page which contian respective methods and objects.
      Programming language: Java(can be python or any other supporting Programming language).
      Data provider from Excel: Read excel using Apache poi.
      Third party jars for running and grouping suites: TestNG
      Logging of scenario steps : log4j
      Reporting: Extent Reporting
      CI/CD jobs for daily report: Jenkins
      Source code management/Version control : Git
      Build tools : Maven, Ant
  5. How to read data from excel sheet in automation frameworks?
    Excel can be read in two ways:
    a. Using jxl – This does not support .xlsx format.
    b. Using Apache POI – Supports both .xls and .xlsx formats.

    Before going to start with our program. Let us visit some excel terminology:
    Workbook(Consists) –> Sheets –> Rows –> Cells
    Cell is the smallest entity whic holds the data.
    And the code in Java for Apache POI:
    HSSF: If excel has extension .xls(ie.,Excel 2003 and earlier) use HSSFWorkbook.
    XSSF: If excel has extension .xlsx(ie.,from excel 2007) use XSSFWorkbook.

    
    package pom.excelreader;        
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Sheet;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    public class myexcelReader {
         
        public static void main(String[] args) throws IOException {
            String excelPath = "myexcel.xlsx";
            FileInputStream inputStream = new FileInputStream(new File(excelFilePath));
            # Using XSSF because xlsx file.
            Workbook wb = new XSSFWorkbook(inputStream);
            Sheet sheet1 = wb.getSheetAt(0);
            Iterator<Row> itrtr = sheet1.iterator();
             
            while (itrtr.hasNext()) {
                Row row = itrtr.next();
                Iterator<Cell> cellItrtr = row.cellIterator();
                 
                while (cellItrtr.hasNext()) {
                    Cell cell = cellItrtr.next();
                     
                    switch (cell.getCellType()) {
                        case Cell.CELL_TYPE_STRING:
                            System.out.print(cell.getStringCellValue());
                            break;
                        case Cell.CELL_TYPE_BOOLEAN:
                            System.out.print(cell.getBooleanCellValue());
                            break;
                        case Cell.CELL_TYPE_NUMERIC:
                            System.out.print(cell.getNumericCellValue());
                            break;
                    }
                }
                System.out.println();
            }
             
            workbook.close();
            inputStream.close();
        }
    }
    
  6. What is folder structure of your project framework??
    This is example scenario of framework where Application Under Test(AUT) consists of 9 Pages as a whole. And each page is having its own functionalities.
    So framework suitable and built is a Page factory model framework on top of Page Object Model basis.
    Folder structure:
    InputOutput- Consists of input properties and Listner classes(to capture output events).
    Lib- It contains all the jars which are used in framework.
    PageObjectClasses- Consists classes for every page in AUT, class consists of Objects and methods of that class.
    SupportingClasses- It has pageBase class which contains common methods and functionalities which can be called across test cases.
    Each pageobject class will extend this class as a parent class. It handles reporting related code too.
    TestCases- It contains the actual test cases and scenarios.
    Reports- It contains screenshots and html reports generated post run.

    Note: There is no thumbrule for framework folder structure. It will depend majorly on AUT and choosen framework design.

  7. What are the challenges faced during development of test cases using selenium?
      While using IE, faced issues because of zoom percentage(Browser zoom level should be set to 100% to resolve this.), SSL certificate and slow execution of send keys . Using same xpath as of firefox resulted in failures in IE.
      Synchronization issues- Happens more when testing dynamic web apps/apps having more Ajax modules.
      Dynamic web application- Where xpath/locators changes happens frequently.
      Some times elements going to stale state because of dom refresh which results staleElementException.
      To upload/download files, explicitly used AutoIT because selenium did not support it.
      SendKeys ignores the “maxlength” attribute in input tags, which could generate false-positive results.
      Need to have must understanding of xpath concepts to write better xpath in case of dynamic elements.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.