屏幕分辨率测试

时间:2012-10-18 20:20:15

标签: testing screen resolution

有没有人知道用于测试不同屏幕分辨率网站的桌面应用?我寻找桌面应用程序的原因是因为我希望能够测试具有内部URL的网站[当然我想以我的计算机上没有的分辨率进行测试。)

谢谢

1 个答案:

答案 0 :(得分:0)

我有类似的问题。您可以为此编写JUnitSelenium测试应用。这不是什么大不了的事,只需更改驱动程序对象的屏幕分辨率并自动获取打印屏幕。图像文件存储在项目中,因此您可以在测试网站的所有分辨率后查看。这是代码:

public class TestCase1 {

    /**
     * 
     */
    private WebDriver driver;

    private String url;

    public TestCase1() {
    }

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
        // array of test urls
        this.url = "http://www.google.com/";

        // ChromeDriver
        //System.setProperty("webdriver.chrome.driver", PATH_TO_CHROMEDRIVER);
        //driver = new ChromeDriver();

        driver = new FirefoxDriver();

        driver.get(this.url);
    }

    @After
    public void tearDown() {
        driver.quit();
    }

    @Test
    public void testResolution() {
        driver.navigate().to(this.url);

        String[] resulutions = {
            "1366x768",
            "1920x1080"
            // add resolution
        };

        for (String resulution : resulutions) {
            String[] parts = resulution.split("x");

            // Screen resolution
            Dimension screenRes = new Dimension(Integer.parseInt(parts[0]),Integer.parseInt(parts[1]));

            // Set browser resolution
            driver.manage().window().setSize(screenRes);

            // little pause
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                //Logger.getLogger(TestClass.class.getName()).log(Level.SEVERE, null, ex);
            }

            driver.navigate().refresh();

            // little pause
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                //Logger.getLogger(TestClass.class.getName()).log(Level.SEVERE, null, ex);
            }

            this.takeScreenShot(resulution);
        }

    }

    /**
     * 
     * @param fileName 
     */
    private void takeScreenShot(String fileName) {
        File screenShot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        try {
            FileUtils.copyFile(screenShot, new File(fileName + ".png"));
        } catch (IOException ioe) {
            throw new RuntimeException(ioe.getMessage(), ioe);
        }
    }

}

以下link用于设置测试项目,导入selenium以及您需要执行此操作的其他人员。