Birlasoft Selenium Recently Asked Interview Questions

How to work with dynamic web table?

You can get the total number of

tags within a

tag by giving the xpath of the

element by using this function –
List ele = driver.findElements(By.xpath(“Xpath of the table”));
Now you can use a for each loop to loop through each of the tags in the above list and then read each value by using getText() method.

Detail about TestNG Test Output folder.

It is the directory where reports are generated. Every time tests run in a suite, TestNG
creates index.html and other files in the output directory.

In frame if no frame Id as well as no frame name then which attribute I should consider throughout our script.

You can go like this…..driver.findElements(By.xpath(“//iframe”))…
Then it will return List of frames then switch to each and every frame and search for the locator which you want then break the loop
Birlasoft Selenium Recently Asked Interview Questions Answers
Birlasoft Selenium Recently Asked Interview Questions Answers

What is object repository?

It is collection of object names their properties, attributes and their values .It maye be excel, XML,property file or text file

TestNG vs. Junit?

Advantages of TestNG over Junit

In Junit we have to declare @BeforeClass and @AfterClass which is a constraint where as in TestNG there is no constraint like this.
Additional Levels of setUp/tearDown level are available in TestNG like @Before/AfterSuite,@Before/AfterTest and @Before/AfterGroup
No Need to extend any class in TestNG.
There is no method name constraint in TestNG as in Junit. You can give any name to the test methods in TestNG
In TestNG we can tell the test that one method is dependent on another method where as in Junit this is not possible. In Junit each test is independent of another test.
Grouping of testcases is available in TestNG where as the same is not available in Junit.
Execution can be done based on Groups. For ex. If you have defined many cases and segregated them by defining 2 groups as Sanity and Regression. Then if you only want to execute the “Sanity” cases then just tell TestNG to execute the “Sanity” and TestNG will automatically execute the cases belonging to the “Sanity” group.
Also using TestNG your selenium test case execution can be done in parallel.

What is the difference between @beforemethod and @beforeclass.

In JUnit4 @Before is used to execute set of preconditions before executing a test.

For example, if there is a need to open some application and create a user before
executing a test, then this annotation can be used for that method. Method that is
marked with @Before will be executed before executing every test in the class.

If a JUnit test case class contains lot of tests which all together need a method
which sets up a precondition and that needs to be executed before executing the
Test Case class then we can utilise “@BeforeClass” annotation.

What are the different Parameters for @Test annotation?

Parameters are keywords that modify the annotation’s function.

Can we run group of test cases using TestNG?

Test cases in group in Selenium using TestNG will be executed with the below options.
If you want to execute the test cases based on one of the group like regression test or smoke test
@Test(groups = {“regressiontest”, “smoketest”})

In what all case we have to go for “JavaScript executor”.

Consider FB main page after you login. When u scrolls down, the updates get loaded. To
handle this activity, there is no selenium command. So you can go for javascript to set
the scroll down value like driver.executeScript(“window.scrollBy(0,200)”, “”);

What are the test types supported by Selenium?

Selenium supports UI and functional testing. As well it can support performance testing
for reasonable load using selenium grid.

Explain about softAssert and HardAssert?

Asserts are used to perform validations in the test scripts.

There are two types of Assert:

Hard Assert
Soft Assert
When an assert fails the test script stops execution unless handled in some form. We call general assert as Hard Assert.

      Hard Assert – Hard Assert throws an AssertExceptionimmediately when an assert statement fails and test suite continues with next @Test.

The disadvantage of Hard Assert – It marks method as fail if assert condition gets failed and the remaining statements inside the method will be aborted.

       To overcome this we need to use Soft Assert. Let’s see what is Soft Assert.

       Soft Assert – Soft Assert collects errors during @Test. Soft Assert does not throw an exception when an assert fails and would continue with the next step after the assert statement.

       If there is any exception and you want to throw it then you need to use assertAll() method as a last statement in the @Test and test suite again continue with next @Test as it is.

       We need to create an object to use Soft Assert which is not needed in Hard Assert.

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();

How to select value in a dropdown?

To handle drop down, an object to be created to the Select class.

Select dropDown= new Select(element);

The value in the dropdown can be selected using 3 ways:

Syntax:

selectByValue()
selectByVisibleText()
selectByIndex()

What is the difference between driver.close() and driver.quit() command?

close(): This method is used to close the current active window of the browser.

quit(): This method is used to close all the associated windows of the browser that are opened.

How to handle Javascript Alerts or web-based pop-ups?

To handle Javascript Alerts, WebDriver provides an Interface called Alert.

First, we need to switch the driver focus to alerts.

Syntax:

Alert alert=driver.switchTo().alerts();

alert.getText() – The getText() method retrieves the text displayed on the alert box.

alert.accept() – The accept() method clicks on the “Ok” button as soon as the pop-up window appears.

alert.dismiss() – The accept() method clicks on the “Cancel” button as soon as the pop-up window appears.

alert.sendKeys(String stringToSend) – The sendKeys() method enters the specified string pattern into the alert box.

How to capture screenshot in WebDriver?

public String getScreenshot() throws Exception {

try {

driver.get(“https://www.google.co.in/”);

driver.findElement(By.linkText(“Gmail”)).click();

return “Pass”;

}

catch(Exception e) {

DateFormat dateFormat = new SimpleDateFormat(“dd-MM-yyyy HH-mm-ss”);

Date dt = new Date();

File screenshotFile = ((TakesScreenshot) d).getScreenshotAs         (OutputType.FILE);

FileUtils.copyFile(screenshotFile, new File(“F:\\Selenium_Scripts_Feb17\\Results\\”+dateFormat.format(dt)+”.png”));

return “Fail”;

}

}

Write a code to login into any site showing uthentication pop-up for username and password?

//Pass Username and Password in URL itself

driver.get(“http://username:password@www.xyz.com”);

How do you send ENTER key?

driver.findElement(By.id(“email”)).sendKeys(Keys.ENTER);

How do you access Firefox profiles in WebDriver?

//create object of ProfilesIni class which holds all the profiles of FF

ProfilesIni pr=new ProfilesIni():

//To load the profile

FirefoxProfile fp=pr.get(“user”);

WebDriver driver=new FirefoxDriver(fp);

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

What are the different types of Waits or Synchrinization commands in WebDriver?

Usually, the time delay between two webdriver elements is 0 milliseconds but the application speed varies based on different factors:

Internet speed
Server response time
System configuration
To avoid the timing errors(Synchronization errors) between the tool (webdriver) and application, we take the help of Synchronization commands.

Implicit Wait: It is used to define wait for all the elements of WebDriver.
Syntax:

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Explicit Wait: It is used to define wait for specific element of WebDriver.
Syntax:

WebDriverWait wait=new WebDriverWait(driver, 30);

wait.until(ExpectedConditions.elementToBeClickable(By.linkText(“Gmail”)));

Post a Comment

Previous Post Next Post