61⟩ Explain me how do you send ENTER/TAB keys in WebDriver?
use click() or submit() methods are used for ENTER. But, don’t forget that submit() method is used only if type=’submit’.
You can use Actions class act.sendKeys(Keys.ENTER) for TAB.
“Automation related Frequently Asked Questions by expert members with professional career as Automation. These list of interview questions and answers will help you strengthen your technical skills, prepare for the new job interview and quickly revise your concepts”
use click() or submit() methods are used for ENTER. But, don’t forget that submit() method is used only if type=’submit’.
You can use Actions class act.sendKeys(Keys.ENTER) for TAB.
Robot API is used to control keyboard or mouse to interact with OS windows like Download pop-up, Alerts, Print Pop-ups, etc. or native Operation System applications like Notepad, Skype, Calculator, etc.
TestNG is a testing framework inspired from JUnit and NUnit in a way to use the merits by both the developers and testers. Here are some new functionalities that make it more powerful and easier to use, such as:
☛ test that your code is multithread safe
☛ support for data-driven testing
☛ support for parameters
☛ a variety of tools and plug-ins support (Eclipse, IDEA, Maven, etc...)
☛ default JDK functions for runtime and logging
☛ dependent methods for application server testing
☛ flexible test configuration
There are four methods of the effective Web-based pop-up handling:
☛ string getText() method returns the text displayed on the alert box
☛ void accept() method clicks on the “Ok” button as soon as the pop-up window appears
☛ void dismiss() method clicks on the “Cancel” button as soon as the pop-up window appears
☛ void sendKeys(String stringToSend) method enters the specified string pattern into the alert box
The different types of locators in Selenium are ID, ClassName, Name, TagName, LinkText, PartialLinkText, XPath, CSS Selector, DOM.
A single slash (/) is used for creating XPaths with absolute paths beginning from the root node.
Double slash (//) is used for creating relative XPath to start selection from anywhere within the root node
Here are some points that favor Python over Java to use with Selenium:
☛ Python is simpler and more compact compared to Java
☛ Java uses traditional braces to start and ends blocks, whilePython uses indentation
☛ Java employs static typing, whilePython is dynamically typed
☛ Java programs tend to run slower compared toPython programs
@DataProvider is concerned to individual test methods and run the specific methods for many times. @Factory method creates test class instances and runs all the test methods in that class with different data. sets.
Here are a few methods of Alerts handling which are widely used in Selenium Webdriver.
☛ void dismiss() is used to click on the 'Cancel' button of the alert.
☛ driver.switchTo().alert().dismiss();
☛ void accept() is used to click on the 'OK' button of the alert.
☛ driver.switchTo().alert().accept();
☛ String getText() is used to capture the alert message.
☛ driver.switchTo().alert().getText();
☛ void sendKeys(String stringToSend) is used to send some data to alert box.
☛ driver.switchTo().alert().sendKeys("Text");
JavaScriptExecuter is used for JavaScript execution in Selenium.
A simple example:
WebDriver driver = new FireFoxDriver();
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor)driver).executeScript("{JavaScript Code}");
}
The following kinds of annotations are used in TestNG:
☛ Test
☛ BeforeSuite
☛ AfterSuite
☛ BeforeTest
☛ AfterTest
☛ BeforeClass
☛ AfterClass
☛ BeforeMethod
☛ AfterMethod
☛ navigate().back() command takes user back to the previous webpage in the web browser’s history. An example: driver.navigate().back();
☛ navigate().forward() lets the user to navigate to the next web page with reference to the browser’s history. An example: driver.navigate().forward();
☛ According to navigate().refresh() command user can refresh the current web page there by reloading all the web elements. An example: driver.navigate().refresh();
☛ User can launch a new web browser window and navigate to the specified URL by executing navigate().to() An example:
driver.navigate().to(“https:// thinkmobiles.com/”);
☛ Functional Testing
☛ Regression Testing
☛ Sanity Testing
☛ Smoke Testing
☛ Responsive Testing
☛ Cross Browser Testing
☛ UI testing (black box)
☛ Integration Testing
The framework is a collection of libraries and classes for helping testers to automate test cases. NUnit, JUnit, TestNG, Bromine, RSpec, unit tests are some of the frameworks available in RC.
We can make one test method run only after successful execution of dependent test method by using dependsOnMethods parameter inside @Test annotation in TestNG: @Test(dependsOnMethods = { "preTests" })
You can get the browser address using these commands. But if you use getWindowHandle(), you’ll get the address of the current browser where the control is and return type is a string. So, if you use getWindowHandles(), you will get the address of all the open browser and its return type is an iterator.
Selenium supports different mouse actions, such as:
☛ click(WebElement element)
☛ contextClick(WebElement element)
☛ doubleClick(WebElement element)
☛ mouseUp(WebElement element)
☛ mouseDown(WebElement element)
☛ mouseMove(WebElement element)
☛ mouseMove(WebElement element, long xOffset, long yOffset)
There are different methods, which help user to check the visibility of the web elements:
☛ isDisplayed(),
☛ isEnabled(),
☛ isSelected().
These web elements can be buttons, drop boxes, checkboxes, radio buttons, labels etc.
Selenium is a suite of tools for automated web testing. It is composed of:
☛ Selenium IDE (Integrated Development Environment). It is a tool for recording and playing back. It is a Firefox plugin.
☛ WebDriver and RC. It provides the APIs for a variety of languages like Java, .NET, PHP, etc. They work with most of the browsers.
☛ Grid: you can distribute tests on multiple machines so that test can be run parallel which helps cutting down the time required for running test suites in the browser.
Both of them let user to find elements in the current web page matching to the specified locator value. But if you use findElement(), only the first matching element would be fetched. An example:
WebElement element = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”))
If you use findElements(), the all matching elements would be fetched and stored in the WebElements list. An example:
List elementList = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));