Java+selenium some small summaries of Web UI Automation testing

Source: Internet
Author: User

-Chrome

About Chrome Configuration Online A lot of information, to be blunt, when choosing to run the use case in the Linux environment, we will choose headless run, by default, headless run browser size seems to be only 900 * 768, our windows cut-through use cases in the narrow serial port often fail, it is better to adjust the size:

Chromeoptions.setheadless (True); Chromeoptions.addarguments ("--no-sandbox"); Chromeoptions.addarguments (" window-size=1280,900 ");

-Firefox,

A. The use cases that can run under Chrome may fail under Firefox, one reason is that Firefox is not operable for all elements that are out of the window, even if using action or JS is not feasible, you need to add the corresponding scrollIntoView ( The following click will describe the specific usage)

B. Firefox is not operational by default for hidden elements (such as uploading a file tag), and Firefox 59 adds Firefoxcapability Moz:wedriverclick for manipulating hidden elements: Firefoxoptions.setcapability ("Moz:webdriverclick", false); Click on hidden elements, such as uploading files

2. About Click

-Element.click

Driver.findelement (BY.CSS). Click (); The condition is visible and the height is greater than 0, which is thrown if the element is clicked (Staleelementreferenceerror

-Action.click

actions = new Actions (driver), action.movetoelement (Element). Click (). Perform ();//Simulate mouse operation, click the middle position of the element

-Javascript scrollIntoView and click

Javascriptexecutorje= (Javascriptexecutor) getwebdriver (); Je.executescript ("Arguments[0].scrollintoview (false);" , Element), or//move to the bottom of the elements object to align with the base of the current window,//true to the top Je.executescript ("Arguments[0].click ();", Element);// By JS Click the element, can be wrapped around the element is covered by the layer or transparent no positive size problem

  

3. Driver

-Chromedriver:

0Headless mode: (Chrome Headless mode does not use XVFB,XVFB as an alternative to the earlier Chrome Headless mode when the X Window Service, Headless default window size is 900x768, can be set by itself)

Chromeoptions.setheadless (True); Chromeoptions.addarguments ("--no-sandbox"); Chromeoptions.addarguments (" window-size=1280,900 ");

Run Chromedriver in 0LINUX/MAC environment need to force set it as executable file

Filefile=newfile ("Chromedriver path"); File.setexecutable (true);

-Geckodriver

Profilesiniprofile=newprofilesini (); Firefoxprofileffprofile=profile.getprofile ("Default"); Capabilities.setcapability (Firefoxdriver.profile, Ffprofile); Setting firefoxoptionsfirefoxoptions=newfirefoxoptions (capabilities) for certificate authentication, firefoxoptions.setcapability ("Moz: Webdriverclick ", false);//allow clicking on hidden elements, such as uploading Files webdriver=newfirefoxdriver (firefoxoptions);

4. Hover

-Hover and click

Actionsaction=newactions (Getwebdriver ()); Action.movetoelement (Element). Perform (); Element.click ();//If there is a problem that cannot be clicked, try changing the movetoelement to the parent node and click the Sub element

  

-Hover and hold

Actionsaction=newactions (Getwebdriver ()); Action.movetoelement (Element). Clickandhold (). Perform ();// Side resolved hover element after doing other operations hover element hidden problem action.release ();

  

Follow slowly add

Java+selenium some small summaries of Web UI Automation testing

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.