SELENIUM2 Learning -024-webui Automation Real-instance -022-site different resolution page style display compatibility problem solution-set browser display area size (unattended, save test cost Gospel, BOSS favorites)

Source: Internet
Author: User

In the process of Web UI automation testing, it is common to test the display of the page at different resolutions, that is, after a full screen browser on a different size display, the test method needs to buy a different size of the display, or frequently set the screen resolution, not only wasted a lot of money, At the same time also need someone on duty, so that the test becomes semi-automatic, deviating from the original intention of the automated testing, but also to a certain extent, plagued by a certain degree of automation testers.

In fact, testing at different resolutions can be seen to some extent as a page-style compatibility test in which the browser can display the area when the browser window is maximized. This article is a way to get rid of all the above problems by setting the size of the browser page display area. Only testers are required to configure a larger display, set the resolution to the maximum, and then, when you start the browser, set the size of the corresponding page display area. Very convenient, and implemented unattended test site at different resolutions page style display compatibility issues.

Refer to the previous few posts (browser window size get and set , get browser display area Size " via Webdriver, via JavaScript" Describes the browser window size of the acquisition and settings, and through Webdriver or JS to get the browser display area size.

On the code, let's gallop!

1     /**2 * Set display screen size3      * 4      * @authorAARON.FFP5      * @versionV1.0.0:autoseleniumdemo main.aaron.sele.core Seleniumcore.java setbrowserscreensize, 2015-7-28 20:52:23 EXP $ 6      * 7      * @paramWidth:screen Width8      * @paramHeight:screen Height9      */Ten      Public voidSetbrowserscreensize (intWidthintheight) { One         //get width and height of window A         intWin_width = This. Webdriver.manage (). window (). GetSize (). getwidth (); -         intWin_height = This. Webdriver.manage (). window (). GetSize (). GetHeight (); -          the         //Get width and height display area -         intDis_width = This. GETBROWSERDISPLAYAREASIZEBYJS () [0]; -         intDis_height = This. GETBROWSERDISPLAYAREASIZEBYJS () [1]; -          +         //Calculate screen width -         intScreen_width = width + win_width-Dis_width; +          A         //Calculate screen Height at         intScreen_height = height + win_height-Dis_height; -          -          This. Setbrowsersize (Screen_width, screen_height); -}

The test source is as follows:

1  Public classTest_setbrowserscreensizeextendsseleniumcore{2     PrivateString baseUrl = "http://www.yixun.com/";3     4 @Test5      Public voidtest_setbrowserscreensize () {6          This. Webdriver =Newchromedriver ();7         8          This. Webdriver.get ("http://www.baidu.com");9         Ten          This. setbrowserscreensize (800, 600); One     } A}

The actual test results are as follows:

At this point, theWebUI automation function test script section 020-javascript in the Selenium Automation application instance of the second (get browser display area size) successfully completed, I hope this article can give beginners Selenium A reference for you.

Finally, very grateful to the pro-stop, I hope this article can be pro helpful. Warmly welcome the kiss to discuss together and progress together. Thank you so much! ^_^

SELENIUM2 Learning -024-webui Automation Real-instance -022-site different resolution page style display compatibility problem solution-set browser display area size (unattended, save test cost Gospel, BOSS favorites)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.