Tuesday, July 7, 2020

Extent Report

Extent report

 

Step1:- Create Maven Project

Step2:- Add below dependency in Pom.xml file

   <!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports -->

<dependency>

    <groupId>com.relevantcodes</groupId>

    <artifactId>extentreports</artifactId>

    <version>2.41.2</version>

</dependency>

    <!-- https://mvnrepository.com/artifact/org.testng/testng -->

<dependency>

    <groupId>org.testng</groupId>

    <artifactId>testng</artifactId>

    <version>6.14.3</version>

    <scope>test</scope>

</dependency>

    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->

<dependency>

    <groupId>org.seleniumhq.selenium</groupId>

    <artifactId>selenium-java</artifactId>

    <version>3.141.59</version>

</dependency>

 

 

Step3:- Create package and Class like below and Add below code (this code will be on official Page)

package com.business.utils;

 

 

 

import java.io.File;

import java.util.Calendar;

import java.util.Date;

import java.util.List;

import java.util.Map;

 

import org.testng.IReporter;

import org.testng.IResultMap;

import org.testng.ISuite;

import org.testng.ISuiteResult;

import org.testng.ITestContext;

import org.testng.ITestResult;

import org.testng.xml.XmlSuite;

 

import com.relevantcodes.extentreports.ExtentReports;

import com.relevantcodes.extentreports.ExtentTest;

import com.relevantcodes.extentreports.LogStatus;

 

public class ExtentReportListener implements IReporter{

     private ExtentReports extent;

 

     public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites,

              String outputDirectory) {

          extent = new ExtentReports(outputDirectory + File.separator

                   + "Extent.html", true);

 

          for (ISuite suite : suites) {

              Map<String, ISuiteResult> result = suite.getResults();

 

              for (ISuiteResult r : result.values()) {

                   ITestContext context = r.getTestContext();

 

                   buildTestNodes(context.getPassedTests(), LogStatus.PASS);

                   buildTestNodes(context.getFailedTests(), LogStatus.FAIL);

                   buildTestNodes(context.getSkippedTests(), LogStatus.SKIP);

              }

          }

 

          extent.flush();

          extent.close();

     }

 

     private void buildTestNodes(IResultMap tests, LogStatus status) {

          ExtentTest test;

 

          if (tests.size() > 0) {

              for (ITestResult result : tests.getAllResults()) {

                   test = extent.startTest(result.getMethod().getMethodName());

 

                   test.setStartedTime(getTime(result.getStartMillis()));

                   test.setEndedTime(getTime(result.getEndMillis()));

 

                   for (String group : result.getMethod().getGroups())

                        test.assignCategory(group);

 

                   if (result.getThrowable() != null) {

                        test.log(status, result.getThrowable());

                   } else {

                        test.log(status, "Test " + status.toString().toLowerCase()

                                  + "ed");

                   }

 

                   extent.endTest(test);

              }

          }

     }

 

     private Date getTime(long millis) {

          Calendar calendar = Calendar.getInstance();

          calendar.setTimeInMillis(millis);

          return calendar.getTime();

     }

}

 

 

 

 

 

Step4:- Create package in Test folder like com.testing and Create Test cases.

package com.test;

 

import java.util.concurrent.TimeUnit;

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.Assert;

import org.testng.annotations.Test;

 

public class DemoTest {

            @Test

            public void getTitle(){

 

                        System.setProperty("webdriver.chrome.driver","C:\\Users\\user\\Desktop\\Driver\\chromedriver.exe");

                        WebDriver driver=new ChromeDriver();

                        driver.get("https://ingenioustechhub.blogspot.com/");

                        driver.manage().window().maximize();

                        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

                        //System.out.println(driver.getTitle());

                        String actual=driver.getTitle();

                        Assert.assertEquals(actual, "asasdasd");

                       

            }

           

            @Test

            public void getTitlePass(){

 

                        System.setProperty("webdriver.chrome.driver","C:\\Users\\user\\Desktop\\Driver\\chromedriver.exe");

                        WebDriver driver=new ChromeDriver();

                        driver.get("https://ingenioustechhub.blogspot.com/");

                        driver.manage().window().maximize();

                        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

                        //System.out.println(driver.getTitle());

                        String actual=driver.getTitle();

                       

                        Assert.assertEquals(actual, "Ingenious TechHub");

                       

            }

           

           

            /*

            @Test

            public void failedTest(){

                        Assert.assertEquals("A", "B");

            }

            */

           

 

}

Step4:- Create XML File and add Listener Tag like below

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Suite">

<listeners>

 

                        <listener class-name="com.qa.extentreport.ExtentReportListener" />

 

            </listeners>

 

 

 

  <test name="Test">

  <classes>

                                    <class name="com.test.DemoTest" />

                        </classes>

  </test> <!-- Test -->

</suite> <!-- Suite -->

 

 

Step5:- Execute Test Cases from XML and Refresh the project,In side test-output folder extent file(Extent.html) will be generated.

 

Step6:- Go to file and open with any browser

 

 

  


Saturday, July 4, 2020

Real Time Interview questions for Automation and Manual Testing profile

Pega Company Interview queation as Automation test Engineer 3 to5 year

=============================================================

1st Round

-----------------

1) What is Roles and Responsibilities in your Current Project

2) What the challenge you faced in your current project

3) How to resolve these challenges

4) If enter Application URL it is not working, what you will do as QA

5)We have tester and We have developer ,Developer having end to end Knowledge for application and Tester having Specifications Requirements document ,How Will find the critical Bug.

6)If you have two work development and Testing Which one you will choose


Q) How To Find Duplicate Characters In A String In Java?

Step1:- Creating a HashMap containing char as key and it's occurrences as value. Step2:- Converting given string to char array. Step3:- ...