Hanging interviewer series: UI automation interview questions summary, benchmarking P7, no longer afraid of interviewers.

Summary of UI automation interview questions

1 Introduction

Xiaodiaosi : Brother Yu, in this season of gold, silver and silver, as a senior test developer (interviewer), can you share your UI automation testing technology?
Xiaoyu : Don't put on a high hat for me, your little thought, can I not know?
Xiao Diaosi : Hehe, I mainly mention
Xiaoyu who our fans asked : Why are you worrying a lot?
Xiao Diaosi : It's mainly the " Hanging and Beating the Interviewer Series: Summary of Interview Questions for Mobile APP Test Development, P7 Positions for Benchmarking" that you shared. It is recommended to collect it! ! ! "Too powerful.
Xiaoyu : You know, I have been preparing the mobile test app for a week,
Xiaodiaosi : Then please spend another week to prepare the knowledge related to UI automation test development, so that more people can feel the slap. "Interviewer" pleasure.
Xiaoyu : This... As a qualified interviewer, how can you be hanged and beaten casually, but your proposal is really good, I will consider it.
Xiao Diaosi : It is said that Impression City has opened a new grilled fish, and it tastes good...
Xiaoyu :…
insert image description here

2. Basics

2.1 How selenium works

  • The script starts the driver;

  • driver to drive the browser as a remote server;

  • Execute the script to send the request;

  • The server parses the request, makes the corresponding operation, and returns it to the client (script);

2.2 The selenium automation page element cannot find the reason for the exception

  • element positioning error;

  • The page loading time is too slow, the element program to be searched has been completed, and the single page has not yet been loaded. At this time, you can load the page waiting time;

  • It is possible that the element is contained in an iframe or frame and needs to be switched;

2.3 How to locate elements whose attributes change dynamically

Attribute dynamic change means that the element has no fixed attribute value and can only be positioned by relative position.

  • The first: traverse with findelements;

  • Second: axis parent/following-sibling/precent-sibling via xpath;

2.4 How to locate dynamically loaded elements on the page

Trigger a dynamic event, and then find element; if it is a dynamic menu, you need to find one level at a time.

2.5 Selenium calls js (execute_script), what are the scenarios

  • perform input on input;

  • Operations on rich text boxes;

  • Scroll to the specified position operation;

2.6 How does selenium handle web pop-ups? js pop-up window?

Need to use driver.switch_to.alert()

2.7 Can selenium handle window pop-ups?

Selenium itself cannot handle windows pop-up windows, but it can use AutoIT gadgets to complete the operation of windows pop-up windows. such as uploading and downloading attachments, etc.

2.8 How to highlight elements after positioning them (for debugging purposes)

Use javascript to change the border or background color of the element to yellow or other colors

2.9 Does selenium support automated testing of desktop application software?

not support. Selenium determines the range of elements based on the attributes of the web page elements

2.10 Does selenium have a library for reading excel files

No, a third-party tool is required.

2.11 Can selenium send the mouse wheel operation to the page

cannot

2.12 How to call the application in webdriver

driver.get(‘url’) 或者 driver.navigate().to(‘url’)

2.13 Common exceptions in selenium

  • NoSuchElementException page element not found exception;

  • ElementNoInteractac tableException;

2.14 Why selenium does not recommend using xpath positioning

Selenium uses the method of traversing pages when using xpath positioning, and the performance indicators are poor. In addition, xpath positioning is located by absolute path, which is sometimes inaccurate;

Using CSS selectors for positioning is simpler and faster, and is usually used in scenarios with strict performance requirements.

2.15 How to determine whether an element exists on a page

  • Method 1: Use try...except to add in the code block;

  • Method 2: Use elements to define a group element method and then return True based on the number of elements len()<1 if it exists, and return False if it does not exist;

  • Method 3: Combine WebDriverWait and excepted_conditions condition judgment (strongly recommended);
    display wait, judge once every 1 second, 30 seconds timeout, return True if it exists, and return False if it does not exist

2.16 How to position dynamic elements

There are two cases for dynamic elements:

  • One is: the attribute is dynamic, when positioning, if the id is dynamic, do not use the id to locate, use other methods to locate the element

  • Another: this element will be at the top of the page and at the bottom for a while, erratic, and the positioning method is the same, according to the element attribute positioning (the tag name attribute of the element will not change, only the class attribute and style attribute move)

2.17 How to locate parent elements by child elements

Locating child elements through parent elements can be found through secondary positioning.

  • The first is to locate the parent element through the child element. Selenium provides the parent method, but it can only locate the parent element, but cannot obtain element attributes and cannot operate.

  • The second: direct positioning through the syntax of xpath. Such as .//*[@name="hello"]/… The two dots represent the parent element.

2.18 How to take a picture of an element, not all pictures

Preferred , intercept the current page and save it as a custom;

Secondly , obtain the coordinates and size of the element according to the attributes of the element image to be intercepted ele.location ele.size

Third , obtain the coordinate size of the image of the element in the following ways:

left = ele.location['x']

 top = ele.location['y']

right = ele.location['x'] + ele.size['width']

 bottom = ele.location['y'] + ele.size['height']

Fourth , open the one that was just saved at the beginning again, use the crop method in the image class (equivalent to copying a rectangular area of ​​the element), and then do the save operation.

2.19 An element is clearly positioned, but the click is invalid (no error is reported), how to solve it

Using js to click, selenium sometimes fails when clicking on an element

 #  js 点击

 js = 'document.getElementById('baidu').click()'

 driver.execute_script(js)

2.20 How to improve the stability of the script

First of all, as long as the page has not changed, the positioning method is no problem.

Optimization direction:

  • Write the relative path yourself, use the id for the node search, and use the right key to copy the xpath, which is unstable.

  • The second influencing factor is waiting, sleep waiting is used as little as possible (affecting execution time)

  • The positioning element method is repackaged, combined with WebDriverWait and excepted_conditions to determine the element method, and encapsulates a set of positioning element methods by itself

2.21 How to improve the execution speed of selenium scripts

  • reduce unnecessary operations;

  • If the page loads too much and does not affect the test, you can set the timeout time to interrupt the page load;

  • When setting the waiting time, you can sleep() for a fixed time, and interrupting the waiting after detecting the appearance of an element can also improve the speed;

  • Configure testNG to implement multi-threading. When writing test cases, be sure to achieve loose coupling, and try to set up multi-threaded operation when the server allows to improve the execution speed;

2.22 When selenium is automated, what problems have you encountered in peacetime? how to solve

Such as dynamic id, the situation of iframe, no waiting and other factors

2.23 Hidden element positioning in selenium, how do you do it

Hidden elements can be positioned normally, but cannot be operated (positioning elements and operating elements are two different things, operating elements refer to methods such as click, clear, send_keys, etc.).
We can use js to manipulate hidden elements.
js is different from selenium, only the elements on the page (in the dom) can operate normally.

2.24 Several ways to upload pictures

send_keys and AutoIT tool implementation

2.25 How to take screenshots

driver.get_screenshot_as_file('图片路径')

3. Advanced

3.1 List the common element positioning methods in web automation?

  • id: Get the element according to the id, return a single element, the id value is generally unique;

  • name: locate according to the name attribute of the element;

  • tagName: locate according to the element's tag name;

  • className: locate according to the style class value of the element;

  • linkText: Position according to the text value of the hyperlink;

  • partialLinkText: Position according to the partial text value of the hyperlink;

  • cssSelector: css selector positioning;

  • xpath: locate by the path of the element;

3.2 Briefly describe the delay waiting method

  • Forced waiting : also called thread waiting, the waiting is completed by thread sleep, such as waiting for 5 seconds: Thread sleep(5000), in general, forced waiting is not used. The main application scenario is where different systems interact.

  • Implicit waiting : Delayed waiting completed by implicitly Wait. Note that this is a waiting for global settings. For example, if the timeout time is set to 10 seconds, after using implicitlyWait, if the element is not found for the first time, it will be within 10 seconds. It keeps looping to find elements. If it is not found for more than 10 seconds, an exception will be thrown. Hard waiting is smarter. It can be configured globally, but it can only be used for element positioning.

  • Explicit waiting : also known as intelligent waiting, the specified waiting time is located for the specified element, the element is searched within the specified time range, and the element is returned directly if the element is found. One of the more flexible waiting methods is that its implementation principle is to continuously try the operations that need to be performed through the while loop.

3.3 How to simulate browser forward and backward, refresh

driver.navigate().back(); //后退
driver.navigate().forward();//前进
driver.navigate().refresh();//刷新

3.4 How Selenium Automation Performs File Upload

If it is the file upload of the input element, it can be passed through the send_keys method in Selenium, but this method is relatively limited. If you encounter components called through js, there will be some problems;
at this time, you need to interact with the system through some way to complete the upload operation, such as operating through third-party libraries such as autoit, pywinauto or pyautogui.

3.5 How to design UI automation test cases

UI automation test cases are extracted from manual test cases. Compared with manual test cases, automated test cases pay more attention to the rigor of use cases. When selecting use cases, follow the following principles:

  • Prioritize use cases that cover the core functionality of the product;

  • From cost considerations, do not choose use cases with overly complex processes;

  • The selected use case can be repeated execution, tedious parts, such as field validation, prompt message validation;

  • Prioritize the implementation of forward test cases, and reverse test cases are generally complex and numerous;

3.6 What is PO mode

PO mode, the full name is Page Object Model, referred to as POM, is the page object mode.
The process of abstracting or modeling a page is to convert a specific page into an object in a programming language, page characteristics into object attributes, and page operations into object methods.

Design each web element of the page as the properties of the page object, and design the operations on the page (such as click, input, etc.) as the behavior of the page object.

In automated testing, it is mainly used to achieve a separation of page operations and test logic. The advantage of this is that business and implementation are separated, making automated test scripts more maintainable.

3.7 What are the encapsulation principles of PO mode?

  • The public method represents a service provided by the page. For example, we can encapsulate the login method into a login method, the search method into a facility method, and the registration operation into a register method;

  • Try not to expose the interior of the page, such as an HTML page and the upper and lower structure of a page;

  • Generally, no assertion is made in PO, and the separation of page logic and test logic will be achieved;

  • The methods in PO generally return self or other Page Object, or it can be an element attribute;

  • The entire PO does not need to encapsulate the behavior of the entire page, just encapsulate whatever logic is used;

  • For the unified operation, if there are different results, it can be expressed in different ways. For example, if the login is successful, there will be a jump, and if the login fails, there will be an error. If the login still has an authorization status, it can be encapsulated into three separate Methods: login success, login error, login invalid.

3.8 How to improve the stability of UI automation scripts

  • Try to use xpath expressions of relative paths;

  • Find element priority with display waiting;

  • Try to avoid dependencies between use cases and use cases, and use cases can be executed independently;

  • Restore the test scenario after the execution of the use case to avoid affecting the execution of other use cases;

  • Add a retry mechanism after script execution fails to improve the stability of the use case;

  • Try to ensure a separate test environment to avoid other tests being carried out simultaneously;

3.9 How to do automated testing based on the web, talk about ideas and directions

Automated testing on the web side is basically simulating manual testers to do functional testing.

Replacing human operations with automated execution of machines.

There are two directions for automated testing of products presented on the web:

  • interface layer
  • interface operation layer,

And the proportion of automation in the interface layer is higher than that in the interface operation layer.

It mainly performs automated testing on the stable functions of the product, and is mainly used for smoke testing and regression testing of the core functions of the product. Start with the core functions of the system, and then slowly expand according to the situation.

3.10 How to do clustering in UI automation testing

  • Selenium Grid, distributed execution use case;
  • Appium uses STF to manage multiple devices;
  • Docker+K8S manages the cluster;

4. Summary

It may be the reason of gold three and silver four, so recently more people have consulted me about interviewing and testing development techniques.
Also because of the good feedback from " Hanging and Beating the Interviewer Series: Mobile APP Test Development Interview Questions Summary, Benchmarking the P7 Position ~ ~ ", and some big bosses hope to sort out other and test development technologies.
Simply, I quit the testing technology on the direction of UI automation,
that is, " Hanging the Interviewer Series: UI Automation Interview Questions Summary, benchmarking P7, and no longer afraid of the interviewer . "
I hope that more test development students can master test development techniques, and at the same time, don't be afraid of the interviewer. After all, there are very few test development interviewers who are too experienced. If you encounter them, you should ask the interviewer for advice, and the interviewer is also People are not impersonal.

Not just casually "abusing" job seekers

So, in the final analysis, to make the interviewer "chat" with you friendly, you need to enrich your technology stack.

Only when you have a rich technology stack will you get a "friendly exchange" from the interviewer.

Guess you like

Origin blog.csdn.net/wuyoudeyuer/article/details/123307329