Desired Capabilities is an class instance of the Capabilities Interface of the web driver library. While we working with web browser automation we need to take the Screenshot of the window to pass or fail the test cases. While i write the scripts to automate the web browsers i need to take the screenshot for reference.
Not only screenshot, to handle the alert such as browser pop up's, Javascript alerts, to enable or disable the SSL Scripts. To handle many other capabilities on the web driver.
We can use takeScreenShot desired capabilities for all browsers such as Firefox/Chrome/IE.
Java API Syntax : public X getScreenshotAs( OutputType target) throws
WebDriverException
Below is an simple code to take the screenshot of your browser windows.
Note: Before you run the scripts make sure you have set the breakpoints on before printing getting Absolute Path. getAbsolutePath is nothing but the screenshot is generated location. In this case, it will be in temp folder. If you not running the code in debugging mode, it will create the screenshot on %Temp% folder and then will be deleted automatically.
To see the Temp folder : For windows users, Go to Run command and enter %TEMP%.
Code:
Not only screenshot, to handle the alert such as browser pop up's, Javascript alerts, to enable or disable the SSL Scripts. To handle many other capabilities on the web driver.
We can use takeScreenShot desired capabilities for all browsers such as Firefox/Chrome/IE.
Java API Syntax : public
WebDriverException
Below is an simple code to take the screenshot of your browser windows.
Note: Before you run the scripts make sure you have set the breakpoints on before printing getting Absolute Path. getAbsolutePath is nothing but the screenshot is generated location. In this case, it will be in temp folder. If you not running the code in debugging mode, it will create the screenshot on %Temp% folder and then will be deleted automatically.
To see the Temp folder : For windows users, Go to Run command and enter %TEMP%.
Code:
import java.io.File; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.OutputType; import org.openqa.selenium.Point; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.remote.DesiredCapabilities; public class BrowserDesiredCapability { public static void main(String args[]) { //Launching firefox browser WebDriver driver = new FirefoxDriver(); //Launching website driver.get("http://www.techyvicky.com/"); //Screenshot syntax and code File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); //Pause your script to see the screenshot - Go to %TEMP% folder to verify System.out.println(scrFile.getAbsolutePath()); } }