How to fetch resolution of screens using Selenium code
For Gui testing aspects java.awt.Dimension and java.awt. Toolkit packages are used to get the screen resolutions whereas the Dimension object stores the result. Inbuilt methods of Dimension class are used to get different aspects of the screen size such as width, height and resolution in pixels which are displayed as double values in the output.
Program below illustrates how to get the screen resolution.
import java.awt.Dimension; import java.awt.Toolkit; public class DetectScreenResolutionBySelenium { public static void main(String[] args) { DetectScreenResolutionBySelenium detectResolution = new DetectScreenResolutionBySelenium(); //creating object of this class detectResolution.displayScreenResolution(); //calling non-static method using object } public void displayScreenResolution(){ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); //get the dimension of screen System.out.println("Screen Width Resolution: " + screenSize.getWidth()); System.out.println("Screen Height Resolution: " + screenSize.getHeight()); int screenResolution = Toolkit.getDefaultToolkit().getScreenResolution(); //get the resolution System.out.println("Screen resolution is : "+screenResolution); } }
Output:
Screen Width Resolution: 1366.0
Screen Height Resolution: 768.0
Screen resolution is : 96
Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.