In Selenium some time IE mouse action will not work properly . Use Below code
*******************************************************************
*******************************************************************
d:- Desiredcapabilities
d.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
d.setCapability("nativeEvents", false);
**************************************************************************
How take Element ScreenShoot ?
Ex: If Login is Fail it will capture error message only instead of complete .
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class screenshot {
@Test
public void cropScreenShot() throws Exception
{
FirefoxDriver fd=new FirefoxDriver();
fd.get("http://www.yahoomail.com");
fd.findElement(By.id("login-username")).sendKeys("Dollar");
fd.findElement(By.id("login-passwd")).sendKeys("sdasad");
fd.findElement(By.id("login-signin")).click();
Thread.sleep(2000);
WebElement we=fd.findElement(By.id("mbr-login-error"));
File v=fd.getScreenshotAs(OutputType.FILE);
BufferedImage bi=ImageIO.read(v);
org.openqa.selenium.Point p=we.getLocation();
int n=we.getSize().getWidth();
int m=we.getSize().getHeight();
BufferedImage d=bi.getSubimage(p.getX(), p.getY(), n, m);
ImageIO.write(d, "png", v);
FileUtils.copyFile(v, new File ("D:\\yahooError.jpg"));
}
}
d.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
d.setCapability("nativeEvents", false);
**************************************************************************
case "ie_driver":
//IE CODE
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "https://testvmm6.partnersonline.com/vmm");
cap.internetExplorer().setCapability("ignoreProtectedModeSettings", true);
System.setProperty("webdriver.ie.driver", System.getProperty("user.dir")+"//exe//IEDriverServer1.exe");
cap.setCapability("IE.binary", "C:/Program Files (x86)/Internet Explorer/iexplore.exe");
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setJavascriptEnabled(true);
cap.setCapability("requireWindowFocus", true);
cap.setCapability("enablePersistentHover", false);
How take Element ScreenShoot ?
Ex: If Login is Fail it will capture error message only instead of complete .
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class screenshot {
@Test
public void cropScreenShot() throws Exception
{
FirefoxDriver fd=new FirefoxDriver();
fd.get("http://www.yahoomail.com");
fd.findElement(By.id("login-username")).sendKeys("Dollar");
fd.findElement(By.id("login-passwd")).sendKeys("sdasad");
fd.findElement(By.id("login-signin")).click();
Thread.sleep(2000);
WebElement we=fd.findElement(By.id("mbr-login-error"));
File v=fd.getScreenshotAs(OutputType.FILE);
BufferedImage bi=ImageIO.read(v);
org.openqa.selenium.Point p=we.getLocation();
int n=we.getSize().getWidth();
int m=we.getSize().getHeight();
BufferedImage d=bi.getSubimage(p.getX(), p.getY(), n, m);
ImageIO.write(d, "png", v);
FileUtils.copyFile(v, new File ("D:\\yahooError.jpg"));
}
}
2 Comments
This is the best blog so far
ReplyDeleteData Science Online Training
Thanks for sharing this great article..Its really nice and useful for us.
ReplyDeleteselenium
Online Training
Post a Comment