Inventory-those automated test interview questions you must know!

Question 1: What is Selenium and what are the popular versions?

It is an open source web automated testing framework, supports multiple programming languages, and supports cross-browser platform testing.
Selenium 1.0 or Selenium RC
Selenium 2.0 or Selenium Webdriver
Selenium 3.0

Question 2: How do you start Selenium RC from the command line?

java -jar selenium-server.jar
// Run a set of Selenese scripts in the
browser java -jar selenium-server.jar -htmlSuite

Question 3: Port 4444 is not free on my machine. How can I use another port?

//You can specify the port when running the selenium server-
Java -jar selenium-server.jar -port 5555

Question 4: What is Selenium Server and how is it different from Selenium Hub?

Selenium Server is an independent application that uses a single server as a test node. Selenium hub proxy one or more Selenium node instances. A hub and multiple nodes are called Selenium grid. Running SeleniumServer is similar to creating a de Selenium grid with a hub and a single node on the same host.

Question 5: How do you connect to the database from Selenium?

Selenium is a Web UI automation tool. It does not provide any API to establish a database connection. It depends on the programming language you use Selenium for automation. In the following example, we assume that Java is being used.
A Connection object represents the connection to the database. When we use the connection method to connect to a database, we create a connection object, which represents the connection to the database. A single database may have one connection or multiple connections, and there may be multiple connections to different databases.
We can use the Connection object to do the following:
create Statement, PreparedStatement and CallableStatement objects for executing SQL statements.
Can help us submit or roll back a JDBC transaction.
If you want to know the database or data source information you are connected to, the Connection object can collect information about the database or data source by using DatabaseMetaData.
Can help us close the data source. The Connection.isClosed() method returns true only when Connection.close() is called. This method is used to close all connections.
First, we need to establish a connection with the database by using the DriverManager.getConnection() method. This method accepts a string containing a URL. The DriverManager class tries to find a driver that can connect to the database represented by the string URL. Whenever the getConnection() method is called, the DriverManager class will check the list of all registered Driver classes that can connect to the database specified in the URL.
Syntax:
String url = "jdbc: odbc: makeConnection";
Connection con = DriverManager.getConnection(url, “userID”, “password”);

Question 6: What are the locator methods in Selenium RC?

ID Name CSS XPATH Dom

Question 7: How do you verify that an object exists on multiple pages?

You can use the following Selenium command to check:
assertTrue(selenium.isElementPresent(locator));

Question 8: What is the difference between single slash and double slash in XPath?

If XPath starts from the document node, it will allow the creation of "absolute" path expressions.
For example, "/html/body/p" matches all paragraph elements.

If XPath starts a selection match anywhere in the document, it will allow the creation of "relative" path expressions.
For example, "// p" matches all paragraph elements.

Question 9: How to write user extensions for Selenium IDE/RC?

User extensions (UX) are stored in a separate file used by Selenium IDE or Selenium RC to activate the extension. It contains function definitions written in JavaScript.
Because the core of Selenium is developed in JavaScript, it must conform to the standard rules of the original language to create extensions. To create an extension, we must write the function in the following design format.
// Sample
Selenium.prototype.doFunctionName = function(){}
The "do" before the function name tells Selenium that this function can be called as a step command, not as an internal function or a private function.

Question 10: How to verify the existence of elements after the page loads successfully?

It can be achieved by the following line of code.
It only takes a moment (in seconds) to inspect the element as follows:

public void waitForElementPresent(String element, int timeout) throws Exception {
for (int second = 0;; second++) {
if (second >= timeout)
fail(“Timeout. Unable to find the Specified element” + element);
try {
if (selenium.isElementPresent(element))
break;
} catch (Exception e) {
}
Thread.sleep(1000);
}}

Question 11: What do you know about Selenium Grid? What function does it provide?

Selenium Grid is a tool that uses existing computing infrastructure to greatly accelerate the functional testing of Web applications. Allows testers to easily run multiple tests in parallel on multiple machines, and can run in a heterogeneous environment.

Based on the excellent Selenium Web testing tool, Selenium Grid allows testers to run multiple Selenium Remote Control instances in parallel. Even better, it integrates and displays all Selenium remote controls, so you don't have to worry about the actual infrastructure. Selenium Grid reduces the time required to run the Selenium test suite to a fraction of the running time of a single instance of Selenium.

Question 12: How to start Selenium server from your Java Class?

try {
seleniumServer = new SeleniumServer();
seleniumServer.start();
} catch (Exception e) {
e.printStackTrace();
}

Question 13: What are the verification points in Selenium?

Selenium has three main verification points-
check page title,
check certain text,
check certain elements (text box, drop-down menu, table, etc.)

Question 14: What is XPath? When should XPath be used in Selenium?

XPath is a method of locating in HTML/XML documents and can be used to identify elements in web pages. If there is no name/ID associated with the element on the page, or part of the name/ID is constant, XPath must be used.
Absolute path use-/ single slash
relative path use-// double slash

ID, class, name can also be used in XPath: br/>//input[@name='q']
//input[@id='lst-ib']
//input[@class=' lst']

If part of id / name / class is constant:
//input[contains(@id,'lst-ib')

Question 15: What is Selenium's CSS locator strategy? Use examples to explain.

The CSS location strategy can be used with Selenium to locate elements. It uses the CSS positioning method, where-
absolute path is-(space symbol)
relative path is ->

ID, class, name can also be used in XPath:
css=input[name='q']
css=input[id='lst-ib'] or input#lst-ib
css=input[class='lst'] or input.lst

If only part of id / name / class is constant:
css=input[id*='lst-ib')]

Element location strategy using internal text:
css = a:contains('log out')

Question 16: What is the mechanism for handling multiple pop-up windows?

You can use the command getWindowHandles() to handle multiple pop-up windows.
Then store all the window names into the Set variable and convert them to an array.
Next, navigate to a specific window by using the array index.
driver.switchTo().window(ArrayIndex);

Question 17: How do you deal with Ajax controls using Selenium?

Let's look at an example. If a text box is an Ajax control, when we enter some text, it will display the automatically suggested value.
To process such a control, you need to capture all suggested values ​​in the string after entering the value in the text box; then, split the string and take the value.

Question 18: What are the advantages of Selenium Webdriver over Selenium RC?

The architecture of Selenium RC is quite complicated, and the architecture of WebDriver is simpler than that of Selenium RC.
Selenium RC is slower because it uses another JavaScript program called Selenium Core. On the contrary, WebDriver is faster than Selenium RC because it talks directly to the browser and uses the browser's own engine for control.

Like other JavaScript code, Selenium Core can access disabled elements. Webdriver interacts with page elements in a more realistic way.
Selenium RC's API set has been improved, but there are still redundant parts that are often confusing. The WebDriver API is simpler and does not contain any redundant or confusing commands.
Selenium RC cannot support the headless HtmlUnit browser. It requires a real, visible browser to operate. Web Driver can support the headless HtmlUnit browser.
Selenium RC has a built-in test result generator and automatically generates an HTML file of the test result. The web driver does not have a built-in command to automatically generate test result files.

Question 19: What is the main difference between "GET" and "NAVIGATE" methods?

The Get method can get a page to load, or get the source code of the page, or get the text, just these three. And Navigate will navigate by refreshing, rewinding, and forwarding.

Partial Link Text. This can be achieved by calling the <navigate()> method.
The driver.get() method will wait until the entire page is loaded, while driver.navigate() just redirects to the page and does not wait.

Question 20: What is the difference between implicit wait and explicit wait?

Implicit wait is a set global wait, divided into 1, page load timeout waiting; 2, page element loading timeout; 3, asynchronous script timeout. If the page element is overtime, setting the waiting time is to set the loading time for all elements in the page. Implicit waiting can actually be understood as the browser keeps refreshing the page within the specified time range until the relevant element is found or the time is over.

The explicit wait is just a timer for a specific search. It is more scalable, you can set it to wait for any conditions. Usually, you can use some pre-built conditions to wait for the element to become clickable, visible, invisible, etc., or just write conditions that suit your needs.

Question 21: How to solve the SSL authentication problem in IE?

// After opening the browser, add the following command
driver.navigate().to("javascript:document.getElementById('overridelink').click()");

Question 22: How to deal with AJAX controls in WebDriver?

AJAX stands for Asynchronous JavaScript and XML. It does not rely on the additional overhead of opening and closing tags required to create valid XML. Most of the time, WebDriver automatically handles Ajax controls and calls. If it cannot be handled, it can be handled in the following way.

//Waiting for Ajax Control

WebElement AjaxElement = (new WebDriverWait(driver,

10)).until(ExpectedConditions.presenceOfElementLocated(By.("")));

Question 23: How to perform mouse movement operations on the submenu items of the title menu?

You should move the menu title first, then move to the pop-up menu item and click on it. Don't forget to call actions.perform() at the end.

Question 24: What is a data-driven framework? How is it different from a keyword-driven framework?

Data-driven framework.
In this framework, the test case logic resides in the test script. The test data is separated and saved outside the test script. The test data is read from an external file (Excel file) and loaded into the variables in the test script. Variables are used to enter values ​​and verify values.
Keyword driven.
The keyword/table-driven framework requires the development of data tables and keywords. They are independent of the test automation tools that execute them. You can design tests with or without applications. In keyword-driven testing, the functionality of the application being tested is recorded in a table, along with step-by-step instructions for each test.

Question 25: Explain the benefits of using TestNG instead of the JUnit framework?

The advantages of TestNG over Junit: In JUnit, we must declare @BeforeClass and @AfterClass, which is a constraint in JUnit, but there is no such constraint in TestNG.
TestNG provides more setUp/tearDown levels.
1. @ Before/AfterSuite 2. @Before/AfterTest 3. @Before/AfterGroup
TestNG does not need to extend any classes.
There are no method name constraints in TestNG, just like JUnit.
In TestNG, we can tell the test that one method depends on another method, which is not possible in JUnit.

The grouping of test cases is available in TestNG, but not in JUnit. Execution can be done on a group basis. For example, if you have defined many cases and separate the two groups as "resignation" and "return". If you just want to perform "sane" situations, tell TestNG to perform "sane" situations. TestNG will automatically execute cases belonging to the "resignation" group.

In addition, TestNG supports parallel test case execution.

Question 26: What is the purpose of the TestNG parameters related to the @Test annotation?

In TestNG, the parameter is the keyword to modify the annotation function.

Question 27: Can I use TestNG to run a set of test cases?

Yes, the TestNG framework supports the execution of multiple test cases with the help of the test group.
It provides the following options to run test cases in a specific group.
If you want to execute test cases based on one of the groups such as regression test or smoke test, then:
@Test(groups = {"regression-tests", "smoke-tests"})

Written at the end:

Don't forget your original intention, go forward courageously, and believe that you will eventually bloom a flower of your own.

Guess you like

Origin blog.51cto.com/15086761/2640944