Adv-Sel-09

 >Selenium Introduction.

-Designed for Web Application Testing

-Free 

-OpenSource

-Platform independant (Supports Multiple OS i.e Windows, Linux, MAC etc.)

-Supports Multiple Browser i.e Chrome, Firefox, Opera, IE, Edge, Safari etc.

-Supports Multiple OOP's Language i.e Java, C#, Ruby, Python etc.

-It is Best Suited for Regression Testing

Test Suite: 

Collection of Test Cases


Selenium Suite: Collection of Tools

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

1.Selenium IDE (Not used in Project)

>It is available as Firefox & Chrome Plug-in/Extension

>It is having very Powerful feature of Record & PlayBack due to this 

scripts are auto- generated.

>Easy to learn 

>No Programmming Skills are required hence best tool for fresher to start  with automation testing


DisAdvantage:

>Supports Testing on only two browser (Chrome & Firefox)

>code re-usability is there since no support of programming

>Connection with Database & Excel Sheet not supported

>No Proper reports are generated( Only logs are generated)


2.Selenium RC | Selenium 1.0 (Outdated Since it is Slow)

DisAdvantage:

1.Selenium RC server acts as Middle Man which adds delay in Execution of Script

2.Selenium RC server also needs time in Starting & Stoping

Both are adding delay in execution Hence Not used in Project

3.Selenium WebDriver | Selenium 2.0 |Selenium 3.0 | Selenium 4.0(About to come)

>Both Supports Multiple Browser Testing (i.e Chrome, Firefox, Opera etc)

>Both Supports Multiple Programming Language.

>Both are Test Designing(Writing Test Scripts) & Test Execution Tool

>Selenium WebDriver is Faster than Selenium RC


Single Machine + Multiple Browser


4.Selenium Grid

>Multiple Machine + Multiple Browser

>Due to Parallel Testing, Less Execution Time will be consumed.

>Various OS & Browser Combination will be done

>It is Only Test Execution Tool (It is not a Test Designing Tool)

Test Designing will be done by WebDriver Only

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

>What is Locators:

It is properties by which Selenium finds Web Object

>id

>name

>linkText

>CSS

>Xpath


>How to work with radio, Checkbox, & dropDown

>Working with Alert

>Excel file Reading & Writing

>FrameWork

>Data-Driven FrameWork

>KeyWord Driven

>Hybrid

>TestNG

>POM(Page Object Model)


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

What is Maven :

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

>Build Tool > Combine all Classes into Single unit (Which is in Machine level       Language)

>Project Management Tool: It gives template/Achitecture/bluePrint of Your Project

>It Manages all External Libraries/Jars




FirstScript


package day1;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.io.FileHandler;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;

public class FirstScript {
	WebDriver driver;
	@Test(priority = 1) // Actual Testing Steps/Task will be Here
	public void titleTest() {
		driver.get("http://bing.com");
		String actualtitle = driver.getTitle(); // Fetching the current page Title
		// ClassNAme.methodName in case of Static Methods
		Assert.assertEquals(actualtitle, "Bing India");
	}
	@Test(priority = 2) // Actual Testing Steps/Task will be Here
	public void searchTest() {
		driver.findElement(By.name("q")).sendKeys("squad");
		driver.findElement(By.name("q")).sendKeys(Keys.ENTER);
		String actualtitle = driver.getTitle(); // Fetching the current page Title
		// ClassNAme.methodName in case of Static Methods
		Assert.assertEquals(actualtitle, "squad - Bing");
	}
	@AfterMethod
	public void afterMethod(ITestResult result) throws Exception{
		if (result.getStatus() == ITestResult.FAILURE) {
			TakesScreenshot tc=(TakesScreenshot)driver;  // It converts driver into takesScreenShot Type
			File src=tc.getScreenshotAs(OutputType.FILE);  // It Takes ScreenShot & Stores in Java's Buffer
			FileHandler.copy(src, new File(result.getName()+".png"));
		}
	}

	@BeforeTest // Pre-condition : Code for Starting Browser
	public void beforeTest() {
		System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver.exe");
		driver = new ChromeDriver(); // Parent p=new Child > driver can hold object of any Child(ChromeDriver)
		/*
		 * WebDriver is a interface & ChromeDriver, FirefoxDriver, & OperaDriver are
		 * Classes which implements WebDriver, TakesScreenShot & JavaScriptExecutor
		 *
		 * Parent p=new Child > driver can hold object of any Child(ChromeDriver,  FirefoxDriver, OperaDriver etc.)
		 * but one disAdvantage it hides Child Specific method
		 */
	}

	@AfterTest // Post-Condition : Code for Stopping browser
	public void afterTest() throws Exception {
		Thread.sleep(2000);
		driver.quit();
	}
}

Comments