September 28, 2018

Srikaanth

ValueLabs Selenium Recently Asked Interview Questions Answers

What is actions class in web driver?

Actions class with web Driver help is Sliding element, Resizing an Element, Drag & Drop,
hovering a mouse, especially in a case when dealing with mouse over menus.
Actions class with web Driver help is Sliding element, Resizing an Element, Drag & Drop
Hovering a mouse, especially in a case when dealing with mouse over menus.

Dragging & Dropping an Element:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class testDragandDrop {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get(“http://jqueryui.com/resources/demos/droppable/default.html”);
WebElement draggable = driver.findElement(By.xpath(“//*[@id=’draggable’]”));
WebElement droppable = driver.findElement(By.xpath(“//*[@id=’droppable’]”));
Actions action = new Actions(driver);
action.dragAndDrop(draggable, droppable).perform();
}
}
Sliding an Element:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class testSlider {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get(“http://jqueryui.com/resources/demos/slider/default.html”);
WebElement slider = driver.findElement(By.xpath(“//*[@id=’slider’]/a”));
Actions action = new Actions(driver);
Thread.sleep(3000);
action.dragAndDropBy(slider, 90, 0).perform();
}
}
Re-sizing an Element:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class testResizable {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get(“http://jqueryui.com/resources/demos/resizable/default.html”);
WebElement resize = driver.findElement(By.xpath(“//*[@id=’resizable’]/div[3]”));
Actions action = new Actions(driver);
action.dragAndDropBy(resize, 400, 200).perform();
}
}

Difference between the selenium1.0 and selenium 2.0?

Selenium 1 = Selenium Remote Control.

Selenium 2 = Selenium Web driver, which combines elements of Selenium 1 and Web driver.

Difference between find element () and findelements ()?

findElement() :
Find the first element within the current page using the given “locating mechanism”.
Returns a single WebElement.
findElements() :
Find all elements within the current page using the given “locating mechanism”.
Returns List of Web Elements.
ValueLabs Selenium Recently Asked Interview Questions Answers
ValueLabs Selenium Recently Asked Interview Questions Answers

How to take the screen shots in seelnium2.0?

public static void captureScreenShot(String filePath) {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(filePath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

}
}

What mobile devices it may Support?

Selenium Web driver supports all the mobile devices operating on Android, IOS operating Systems

Android – for phones and tablets (devices & emulators)
iOS for phones (devices & emulators) and for tablets (devices & emulators)

Write down scenarios which we can’t automate?

Barcode Reader, Captcha etc.

In TestNG I have some test’s Test1-Test2-Test3-Test4-Test5I want to run my execution order is Test5-Test1-Test3-Test2-Test4.How do you set the execution order can you explain for that?

Use priority parameter in @test annotation or TestNG annotations.
public class testngexecution { @Test(priority=2)public void test1(){System.out.print(“Inside Test1”); }@Test(priority=4)public void test2(){System.out.print(“Inside Test2”); }@Test(priority=3)public void test3(){System.out.print(“Inside Test3”); }@Test(priority=5)public void test4(){System.out.print(“Inside Test4”); }@Test(priority=1)public void test5(){System.out.print(“Inside Test5”); }

Differences between jxl and ApachePOI.

jxl does not support XLSX files
jxl exerts less load on memory as compared to ApachePOI
jxl doesn’t support rich text formatting while ApachePOI does.
jxl has not been maintained properly while ApachePOI is more up to date.
Sample code on Apache POI is easily available as compare to jxl.

How to ZIP files in Selenium with an Example?

// Sample Function to make zip of reports
public static void zip(String filepath){
try
{
File inputFolder=new File(‘Mention file path her”);
File outputFolder=new File(“Reports.zip”);
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputFolder)));
BufferedInputStream in = null;
byte[] data = new byte[1000];
String files[] = inputFolder.list();
for (int j=0; j<files.length; i++)
{
in = new BufferedInputStream(new FileInputStream
(inputFolder.getPath() + “/” + files[j]), 1000);
out.putNextEntry(new ZipEntry(files[j]));
int totalcount;
while((totalcount= in.read(data,0,1000)) != -1)
{
out.write(data, 0, totalcount);
}
out.closeEntry();
}
out.flush();
out.close();
}
catch(Exception e)
{
e.printStackTrace();
return “Fail – ” + e.getMessage();
}
}

What is default port no?

4444

If Default port no is busy how to change port no?

We can use any port number which is valid.. First create an object to remote control configuration.
Use ‘setPort’ method and provide valid port number(4545,5555,5655, etc).. There after attach this
remote control configuration object to selenium server..i.e
RemoteControlConfiguration r= new RemoteControlConfiguration();
r.setPort(4567);
SeleniumServer s= new SeleniumServer(r);

Does Selenium support https protocols?

Yes

Majorly asked test scenario with framework in Interviews?

Majorly asked are:

Login for Gmail scenario
Goggle search and finding no of results
Downloading a file and save it
Checking mails and deleting them
Do shopping in flipkart.com

Selenium support mobile applications?

No, it is browser automation tool, it only automates Websites opening in mobile browser, and mobile APPs can’t be automated.

What is wraps Driver?

For casting selenium instance to selenium2 (webdriver). wraps driver is used.

Can you explain Junit Annotation? If there are 1000 test cases. 500 test cases are executed. How will you execute the rest of the test cases by using annotation?

The annotations generated with JUnit 4 tests in Selenium are:

@Before public void method() – Will perform the method() before each test. This method can prepare the test
@Test public void method() – Annotation @Test identifies that this method is a test method.environment,e.g. read input data, initialize the class)
@After public void method() – Test method must start with test@Before – this annotation is used for executing a method before

Difference between assert and verify in selenium web driver.

When an “assert” fails, the test will be aborted. Assert is best used when the check value has to pass for the test to be able to continue to run log in.
Where if a “verify” fails, the test will continue executing and logging the failure. Verify is best used to check non critical things. Like the presence of a headline element.

“I want to find the location of “”b”” in the below code, how can I find out without using xpath, name,id, csslocator, index.
a
b
c
• driver.findElement(By.xpath(“//*[contains(text(),’b’)]”)).click(); or
• //div/button[contains(text(),’b’]

How to do Applet testing using selenium?

Please see below URLs:
http://docs.codehaus.org/display/FEST/Selenium
https://code.google.com/p/festselenium/.

How to Start Jenkins in command Promt?

D:\>Java –jar Jenkins.war

What is the latest version of Jenkins?

      Jenkins 2.114

What is Page Object Model?

Page Object Model Framework has now a days become very popular test automation framework in the industry and many companies are using it because of its easy test maintenance        and reduces the duplication of code.

    The main advantage of Page Object Model is that if the UI changes for any page, it don’t require us to change any tests, we just need to change only the code within the page objects        (Only at one place).

The Page Object model provides the following advantages.

There is clean separation between test code and page specific code such as locators (or their use if you’re using a UI map) and layout.
There is single repository for the services or operations offered by the page rather than having these services scattered throughout the tests.

What is the default port for selenium Grid?

      The default port used by the hub is 4444

Selenium advantages and disadvantages?

Advantages:

Selenium is pure open source, freeware and portable tool.
Selenium supports variety of languages that include Java, Perl, Python, C#, Ruby, Groovy, Java Script, and VB Script. etc.
Selenium supports many operating systems like Windows, Macintosh, Linux, Unix etc.
Selenium supports many browsers like Internet explorer, Chrome, Firefox, Opera, Safari etc.
Selenium can be integrated with ANT or Maven kind of framework for source code compilation.
Selenium can be integrated with TestNG testing framework for testing our applications and generating reports.
Selenium can be integrated with Jenkins or Hudson for continuous integration.
Selenium can be integrated with other open source tools for supporting other features.
Selenium can be used for Android, IPhone, Blackberry etc. based application testing.
Selenium supports very less CPU and RAM consumption for script execution.
Selenium comes with different component to provide support to its parent which is Selenium IDE, Selenium Grid and Selenium Remote Control (RC).

Disadvantages:

Selenium needs very much expertise resources. The resource should also be very well versed in framework architecture.
Selenium only supports web based application and does not support windows based application.
It is difficult to test Image based application.
Selenium need outside support for report generation activity like dependence on TestNG or Jenkins.
Selenium does not support built in add-ins support.
Selenium user lacks online support for the problems they face.
Selenium does not provide any built in IDE for script generation and it need other IDE like Eclipse for writing scripts.
Selenium Automation Engineers are bit in scarcity these days.
Selenium script creation time is bit high.
Selenium does not support file upload facility.
Selenium partially supports for Dialog boxes.

From Which selenium version onwards –we have to use gecko driver for firefox?

Selenium 3.0

How to skip a test case in TestNG?

@Test(enabled=false) annotation is used to skip a test case in TestNG

How to find whether an element is a Multidrop down or not?

By using isMultiple()

For example:

Boolean b=driver.findElement(By.id(“year”)).isMultiple();

System.out.println(b);

It retuns true if the element is multi drop down else false

What is the difference between getText() and getAttribute() ?

getText(): It is used to retrieve the text of a Text Element from the web page

For Example:

String Text = driver.findElement(By.id(“Text”)).getText();

getAttribute(): It is used to retrieve the text from a Text Field that is already eneterd into the text field.

For Example:

String Text = driver.findElement(By.id(“username”)).getAttribute();


Subscribe to get more Posts :