Steps
1/ 	Download Java JDK from path >> https://www.oracle.com/java/technologies/downloads/#jdk17-windows
2/ 	Install the Java
3/ 	Downlpad Eclipse from >> https://www.eclipse.org/downloads/packages/
4/ 	Open Eclipse and download Maven [from Eclipse Market place] if required, otherwise check if Maven is already installed
5/ 	Create New Project > Select Maven Folder > Select Maven Project
6/ 	Copy POM file sample from "https://qa-testing-all.blogspot.com/p/pom.html"
7/ 	Click on Maven - Update Project, RunAs Maven Install
8/ 	Download qeckodriver from >> https://github.com/mozilla/geckodriver/releases
9/ 	Install TestNG from Market place
10/   Create Class file & copy paste below code to execute the script
11/   Implement rest of the test cases...
**********************************************************************
package Selenium_Files;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.*;
public class UI_Sample {
public String baseUrl = "http://demo.guru99.com/test/newtours/";
String driverPath = "C:\\Users\\<User Name>\\Automation\\Software\\geckodriver-v0.30.0-win64\\geckodriver.exe";
public WebDriver driver;
	@Test
	public void verifyHomepageTitle() {
		System.out.println("launching firefox browser");
		System.setProperty("webdriver.gecko.driver", driverPath);
		driver = new FirefoxDriver();
		driver.get(baseUrl);
		String expectedTitle = "Welcome: Mercury Tours";
		String actualTitle = driver.getTitle();
		Assert.assertEquals(actualTitle, expectedTitle);
		// driver.close();
	}
}
*********************************************************
package Selenium_Files;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.*;
public class UI_Sample1 {
public String baseUrl = "http://demo.guru99.com/test/newtours/";
String driverPath = "C:\\Users\\Ravi Konka\\Automation\\Software\\geckodriver-v0.30.0-win64\\geckodriver.exe";
public WebDriver driver ; 
 
	     @BeforeTest
	      public void launchBrowser() {
	          System.out.println("launching firefox browser"); 
	          System.setProperty("webdriver.gecko.driver", driverPath);
	          driver = new FirefoxDriver();
	          driver.get(baseUrl);
	      }
	      @Test
	      public void verifyHomepageTitle() {
	          String expectedTitle = "Welcome: Mercury Tours";
	          String actualTitle = driver.getTitle();
	          Assert.assertEquals(actualTitle, expectedTitle);
	     }
	      @AfterTest
	      public void terminateBrowser(){
	          driver.close();
	      }
}
*********************************************************
Extent Report
*********************************************************
2/ Save the POM.xml file
3/ Add the below code in the new class file
**********************************************************
	package Selenium_Files;
	
	import java.io.File;
	import org.openqa.selenium.WebDriver;
	import org.openqa.selenium.firefox.FirefoxDriver;
	import org.testng.annotations.AfterMethod;
	import org.testng.annotations.AfterTest;
	import org.testng.annotations.BeforeMethod;
	import org.testng.annotations.BeforeTest;
	import org.testng.annotations.Test;
	import com.relevantcodes.extentreports.ExtentReports;
	import com.relevantcodes.extentreports.ExtentTest;
	import com.relevantcodes.extentreports.LogStatus;
	
	public class UI_Sample_Extent_New {
		// Extent report initialization
		ExtentReports extent;
		ExtentTest logger;
	
		// Browser initialization
		public String baseUrl = "http://demo.guru99.com/test/newtours/";
		String driverPath = "C:\\Users\\Ravi Konka\\Automation\\Software\\Drivers\\geckodriver.exe";
		public WebDriver driver;
	
		@BeforeTest
		public void startReport() {
			// Extent Reports code
			extent = new ExtentReports(".\\results\\ExtentReport.html", true);
			extent.addSystemInfo("Host Name", "Sample Selenium").addSystemInfo("Environment", "Automation Testing")
					.addSystemInfo("User Name", "KONKA RAVI");
			extent.loadConfig(new File(System.getProperty("user.dir") + "\\config\\extent-config.xml"));
	
			// Browser Code
			System.setProperty("webdriver.gecko.driver", driverPath);
			driver = new FirefoxDriver();
			driver.get(baseUrl);
		}
	
		@BeforeMethod
		public void startLogger() {
			logger = extent.startTest("FireFox Testing");
		}
	
		@Test
		public void passTest() throws Exception {
			// Browser Code
			String expectedTitle = "Welcome: Mercury Tours1";
			String actualTitle = driver.getTitle();
			addResultData(expectedTitle, actualTitle);
		}
	
		public void addResultData(String exceptedResult, String actualResult) throws Exception {
			if (exceptedResult.equals(actualResult)) {
				System.out.println("PASS");
				logger.log(LogStatus.PASS, "Test Case Passed");
			} else {
				System.out.println("FAIL");
				logger.log(LogStatus.FAIL, "Test Case Failed");
			}
		}
	
		@AfterMethod
		public void endLogger() {
			extent.endTest(logger);
		}
	
		@AfterTest
		public void endReport() {
			// Extent Report Code
			extent.flush();
			extent.close();
			// Browser Code
			driver.close();
		}
	
	}
*****************************************************************
Chrome Browser Example
1/ Download chrome driver > check the chrome browser version to download the driver
*****************************************************************
package Selenium_Files;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class UI_Sample_Chrome {
    public String baseUrl = "http://demo.guru99.com/test/newtours/";
    String driverPath = "..\\drivers\\chromedriver.exe";
    public WebDriver driver ; 
     
     @BeforeTest
      public void launchBrowser() {
          System.out.println("launching chrome browser"); 
          System.setProperty("webdriver.chrome.driver", driverPath);
          driver = new ChromeDriver();
          driver.get(baseUrl);
      }
      @Test
      public void verifyHomepageTitle() {
          String expectedTitle = "Welcome: Mercury Tours";
          String actualTitle = driver.getTitle();
          Assert.assertEquals(actualTitle, expectedTitle);
     }
      @AfterTest
      public void terminateBrowser(){
          driver.close();
      }
}
 
 
No comments:
Post a Comment