Interview preparation --selenium common interview questions and answers (java)

Automated testing interview --selenium Basics

Objective: To investigate familiarity seekers in positions of selenium automated testing tools

1. how to determine whether there is an element?

Judge element exists and whether there are different, this means that if there is to determine whether the elements simply do not exist, will throw NoSuchElementException

So you can use try catch, if the catch to NoSuchElementException returns false . This function will usually isElementPresent packaging method in the project.

2. How to determine whether there is an element?

Determining whether there is an element, there are two cases, one is the element they not, does not occur naturally; another is such elements, but the state is hidden

By first determining whether there is, if there is no return false; if there is again determined whether displayed.

Whether 3.selenium in hidden or display = none of the elements can be targeted to?

Not, want to click on, you can use js remove dispalay = none attribute.

4. selenium in how to ensure the success rate of the operation elements? That is how to ensure that I click on certain elements are clickable?

1. waitforEmelentPresent achieved by encapsulating the find method, so that prior to the operation to ensure that the element is found elements, thereby improving the success rate

2. Before operating elements, such as click, if the element is not display (non-hidden), you need to scroll to the element, and then click operation; why use the scroll? Because if the page is not completely displayed, element if it is to appear in the drop-down after it, can only scroll to the first element to be click, otherwise it is not click operation

1
2
3
JavascriptExecutor js=(JavascriptExecutor)driver;
         // roll down and keep the element to the center of browser
         js.executeScript( "arguments[0].scrollIntoViewIfNeeded(true);" , download);

3. positioned in different ways, with the determination method of the package expectedConditions cycle occurs after the operation is determined page elements;

4. developers to standardize the development of habits, such as page elements to add a unique name, id and so on.

5. How to locate elements on the page dynamically loaded?

    Dynamic event trigger, then findElemnt

    If the menu is dynamic, you need a find a (JS achieve)

6. How to locate the element attributes dynamic?

  Dynamic changes of properties means that the property value element is not fixed, it can only be positioned relative position

    Xpath such as by the shaft, parent / following-sibling / precent-sibling, etc.

    Alternatively, you can try to traverse findbyelements

7. After clicking the link, selenium whether to wait for the page is automatically loaded?

Will not. So sometimes, when selenium did not finish loading a page again when the page is requested resources, the absence of this element will be false positives. So first we should consider to determine whether selenium been loaded this page. Secondly, and then look for the elements by function.

8. automated testing whether the time need to connect the database to do data validation?

Generally 1, UI Automation not required (rarely needed); 2, test interfaces will need: to verify the data from the database level can more easily verify data processing system are correct;

9. There are several common elements targeting, respectively? Which one do you most prefer, and why?

Eight kinds: id, name, class name, tag name, link text, partial link text, xpath, css selector preference which one? answer:

I am most commonly used is the xpath (or CssSelector) because in many cases, property html tags are not standardized, can not, at this time can only use a single attribute xpath can go to re-locate to achieve a unique positioning element

In fact the fastest positioning is Id, because id is unique, but most developers do not set the id.

10. how to improve the efficiency of selenium script automation?

1. Optimization of test cases, as much as possible without using SLEEP, reduce ImplicitlyWait

2. Multi-use selenium in WebDriverWait / FluentWait, so the waiting time can be optimized

3. Reduce unnecessary steps, such as through the San Sibu to open the page we want to test, then we will be able to open directly through the Web site, reducing unnecessary operations.

4. Interrupt page load, if the page loaded content too much, we can look at the reasons for slow loading, if the loaded content does not affect our test, we set the timeout interrupt the page loads.

5. Use good performance computer

11. The use cases would often unstable during operation, that is, by this time, next time can not pass, and how to improve the stability of the use case?

1, prior to find elements do first determination: ExpectedConditions inside various methods;
2, the explicit wait: the use of multiple WebDriverWait, together with an explicit wait time, etc. to be operated after the element appears then perform the following operations;
3, multi-try catch catch the exception;
4, when the multi-threaded, to reduce the degree of coupling test cases, as the execution order multithreading is uncontrolled;
5, try to use a test environment, avoid other types of tests simultaneously, causing interference to the data.

12. What are your automated execution strategy is the use case?

1. Automated test is used to monitor. Integrated into jenkins, create a scheduled task to perform regular;
2. Some use cases must return before the on-line products. jenkins task bound to build on the task of developing the trigger execution;
3. Some patients do not need to use often. jenkins create a task, when you need to perform artificial construct can be.

13. What is Continuous Integration?

Frequent code integrated into the trunk, the framework of sustainability of the project in order to be able to quickly find errors that prevent a substantial deviation from the trunk branch

What is the principle 14.webdriver client is?

After selenium start, driver acted as servers, communication with the client and browser, client sends a request to the driver webdriver according to the agreement. driver resolution request, and performs a corresponding operation on the browser, and returns the execution result to the client.

What 15.webdriver protocols are?

The Wire Protocol

16. Start the browser used when webdriver which protocol ?

http

17. What is PO mode, what is the page factory?

    PO mode is the abbreviation for page object model, by definition, is a design pattern, the objects on each page as a page, page layers positioned element method and write a page method of operation, to achieve real page and Web page scripts Map up a a correspondence. This will test framework easier to maintain. For example, a landing page, after use PO mode, creates a LoginPage the class, webElenent the class defines a user name input box, the password input box, login button; use cases layers from the page layer calls operating method, written in cases, this model positioning the separation of elements can be done with the script. So this design philosophy is PO mode. The PageFactory under the PO mode, is used to initialize each PO mode to achieve the Page Class, initialize the object library.

18. How to choose a drop-down box value = xx's option?

Method 1.select provided inside the class: selectByValue ( "xxx")
syntax may also be positioned to 2.xpath

19. How highlighting elements in the positioning element?

Reset the element properties, to add background element positioning, border

20.get and post the difference?

1, GET request: the requested data will be appended to the URL, the URL and transmit the divided data to a plurality of connection parameters &?.
   POST request: POST request will request data packet is placed in the body of the HTTP request packet.
2, the size of transmission data
using a GET request, the transmission data is limited by the length of the URL.
For POST, in theory, it is not restricted
3, security. Security is higher than the GET POST

First point, followed by subsequent summary .....

 

Guess you like

Origin www.cnblogs.com/gaogo/p/11442375.html