August 27, 2019

Srikaanth

Lenovo Selenium Recently Asked Interview Questions

Write Syntax for Double Click?

Actions act = new Actions(driver);

action.doubleClick(element).build().perform();

Write Syntax for Right Click?

Actions act = new Actions(driver);

action.contextClick(element).build().perform();

Difference between Apache POI and Jxl jar files?

JExcel Apache POI
It doesn’t support Excel 2007 and Xlsx format. It supports only Excel 2003 and .Xls format It supports both
JXL doesn’t support Conditional formatting It supports
JXL API was last updated in 2009 Apache POI is actively maintained
It doesn’t support rich text formatting Apache POI supports it
It has very less documents and examples as compare to Apache POI It has extensive set of documents and examples
Lenovo Selenium Recently Asked Interview Questions Answers
Lenovo Selenium Recently Asked Interview Questions Answers

What are all the element locators in Selenium?

Id

Name

CSSSelector

Xpath

Tagname

ClassName

LinkText

Partial LinkText

How to Handle Dropdown Values in selenium. Write a syntax and types to handle the dropdpwn Box?

Using with Select Class

Syntax:

     Select sel = new Select(driver.findElement(By.id(“test”));

     Sel.SelectByVisibleText(“value”);

     Sel.SelectByValue(“2”);

     Sel.SelectByIndex(4);

When will you get element not clickable exception in Selenium?

The reason for the element is not clickable at point(x,y) exception.

      Some of my observation was

It mostly happens in Chrome so if you are mostly working with Firefox or IE then you will not be getting this exception.
Chrome does not calculate the exact location of element
Chrome always click in the middle of Element.
Sometimes you will get this exception due to Sync issue also.

How to solve Not connected Exception – unable to connect to host in selenium webdriver?

Scripts that worked earlier may be till yesterday are NOW not working because of Firefox browser upgraded to new version.

      Most of them have faced the similar problem when the browser has updated to version. This is the first issue user notices when there is an update in the Firefox browser and may not support selenium with the older version of jars.

      If you already have the latest version of selenium, then you have to degrade your browser until there is an update from selenium.

      Problem :

      Webdriver will just initiate the browser, prompting for a search or address and that ends there with an exception:

      org.openqa.selenium.firefox.NotConnectedException:

What is Selenium?

Selenium is a Suite (group) of tools i.e., Selenium IDE, Selenium WebDriver and Selenium Grid to automate web browsers across many platforms.

What is Selenium IDE, WebDriver, and Grid?

Selenium IDE: It is a Firefox plugin which is used to Record and Play the Test Scripts.

Selenium WebDriver: It is a tool which provides an API (that can be understood easily) to automate web browsers with the help of programming languages like Java, Csharp, Python, PHP, Perl, Ruby, and JavaScript.

Selenium Grid: It transparently distributes tests into Remote machines. That is, running multiple tests at the same time against different machines running different browsers and operating systems.

What are the locators available in WebDriver?

Locators: Locators are used to identifying or locate an element (text box, radio buttons, links, check boxes, drop downs, images, text etc. ) in the web page.

Webdriver supports 8 locators i.e., Id, Name, Class Name, Link Text, Partial Link Text, XPath, CSS and Tag Name.

Note: Id is the fastest locator among this 8 locators.

How to launch Firefox, Chrome, IE browser using WebDriver?

The following syntax can be used to launch Browser:

WebDriver driver = new FirefoxDriver();

WebDriver driver = new ChromeDriver();

WebDriver driver = new InternetExplorerDriver();

How to set System Property in WebDriver?

We can set the system property by using setProperty() method, which is a static method defined in System class for which we need to pass 2 parameters i.e., driver name and path of the executable file of the driver.

For Example Setting system property to launch chrome browser

public class ChromeBrowser {

WebDriver driver;

public static void main(String[] args) {

System.setProperty(“webdriver.chrome.driver”, “E://chromedriver.exe”);

driver = new ChromeDriver();

driver.get(“http://www.google.com”);

}

}

How to find font color of Text element?

By using getCssvalue()

For example:

driver.findElement(By.id(“text”)).getCssValue(“color”);

How to find size of the Image?

By using getSize()

How to find Dynamic Web Elements?

We can Dynamic web elements with the help of XPath or CSS.

For Example:

By using XPath:

driver.findElement(By.xpath(“//div[contains(@id,’yui_’)]”));

By using CSS:

driver.findElement(By.cssSelector(“div[id*=’yui_’)]”));

How to skip a test case in JUnit?

By using @Ignore annotation

@Ignore

@Test

public void testDemo(){

System.out.println(“This is testDemo Method”);

}

@Test

public void testPractice(){

System.out.println(“This is testPractice Method”);

}

Output:

This is testPractice Method

Note: Execution in JUnit is carried out in Alphabetical Order


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/


Subscribe to get more Posts :