Android Basic Interview Questions

android basic interview questions

Android Developer Interview Questions

1.What is android?

 Android is open source Linux based operating system with middle ware and some key applications

2.What are the advantages of android?

Open-source:

It means no licence, distribution and development fee.

Platform-independent: 

Android is platform independent we can develop applications in mac, Linux and windows also by using android studio

Supports various technologies:

It supports camera, Bluetooth, WiFi, speech, EDGE etc. technologies.

DVM :

DVM is highly optimized virtual machine which will convert to .dex file

3.What is an Activity?

Activity is like a frame or window in java that represents GUI. It represents one screen of android.

4.What is Activity life cycle?

There are 7 life-cycle methods of activity. They are as follows:

  1. onCreate() — called when activity is first created.
  2. onStart() — onStatrt will invoked  when activity is becoming visible to the user.
  3. onResume() — onResume will invoked when activity will start interacting with the user.
  4. onPause() onPause will invoked when activity is not visible to the user.
  5. onStop() — onStop will invoked if activity is no longer visible to the user.
  6. onRestart() — onRestart will invoked if your activity is stopped and prior to start.
  7. onDestroy() — onDestroy will invoked before the activity is destroyed

5.What is the difference between margin and padding?

if you want to take your widget like TextView, EditText far away from other. You should use margin from top,right,left,bottom.

By giving padding the component size will be increased  

6.What is the difference between gravity and layout_gravity?

android:gravity Is to specify to place content with in the object.if gravity is left means object content is going to be left to the component.

android:layout_gravity is an attribution the child can supply to its parent, to specify the gravity the view within its parents

7.What is APK?

APK means Android Package Kit.android is going to make apk file with all resources and code to install on mobile phone

8.What DVM and difference between DVM and JVM?

DVM means Dalvik Virtual Machine

DVM is Register based and specially designed to run on low memory

uses its own byte code and runs .Dex file

JVM is Stack based and convert all java code to .class files

9.What is AndroidManifest.xml?

Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory.We will register every activity ,services,broadcast receivers and content providers.We will declare all permissions in manifest file only.

10.What is a service in android?

Service is a background process that can run for a long time even after closing activity also.

11.What is Content Provider?

Content Providers are used to share data between the applications.

12.What is Broadcast Receiver?

A broadcast receiver (receiver) is an Android component it allows you to register for system events Like calls, notifications. Once we register a receiver, automatically receiver is going to call once that functionality is triggered.

 

1. What is default package of selenium?
2. Maximizing Browser Window?
3. What are the prerequisites to run selenium webdriver?
4. What are the flavors of selenium ?
5. Diff b/w Verify and Assert ?
6. How to Verify Element is visible or not?
7. Verify Single checkbox is selected or Not ?
8. Verify Multiple checkboxes are selected or Not ?
9. How to handle Popup window ?
10. How to perform double click in selenium?
11. How to select dropdown value inside a frame?
12. How to get all the frames on webpage ?
13. How Switch back to Main page from Frame ?
14. Suppose I have two submit buttons with same names on Webpage, here how can u click on 1st submit button.
15. How to scroll webpage to particular WebElement ?
16. How to read and verify Font Properties?
17. Diff b/w cssSelector and xpath ?
18. How to verify particular text in a webpage ?
19. Diff b/w driver.getwindowhandle() and driver.getwindowhandles()?
20. Which Programming Languages Supported By Selenium WebDriver To Write Test Cases?
21. Which Different Element Locators Supported By Selenium WebDriver?
22. What Is XPath and what Is use of It In WebDriver?
23. Which tool you are using to find the XPath of any element?
24. Can you tell me a difference between driver.get() and driver.navigate() methods?
25. Which Programming Languages Supported By Selenium WebDriver To Write Test Cases?
26. What Is XPath and what Is use of It In WebDriver?
27. How to handle Web Based Popups?
28. How to handle single Popup window ?
29. Can we automate desktop software application’s testing using selenium WebDriver?
30. Can we perform drag and drop operation In Selenium WebDriver?
31. How to verify successful message in a webpage ?
32. How do you identify the Xpath of element on your browser ?
33. What is the difference between absolute XPath and relative XPath?
34. How to Create customized xpath in selenium ?
35. How To Handle Dynamic Changing IDs In XPath. ?

Example :
Xpath= //div[@id=’post-body-3647323225296998740′]/div[1]/form[1]/input[1]

In this XPath “3647323225296998740” Is changing every time when reloading the page. How to handle this situation?

36. Tell me a reason behind bellow given WebDriver exception and how will you resolve It?

“Exception in thread “main” org.openqa.selenium.NoSuchElementException: Unable to locate element”

37. Can you tell me a syntax to close current webdriver Instance and to close all opened webdriver Instances?
38. What Is the syntax to get value from text box and store It In variable. ?
39. How to capture screenshot when test case failure In selenium webdriver ?
40. Tell me any 5 webdriver common exceptions which you faced during software test case execution. ?
41. What is Difference between getAttribute() and getText()?
42. To verify whether the particular text is present or not on the page ?
43. Why need Ant-XSLT-Reports in selenium WebDriver. ?
44. What is a framework and Advantages of framework. ?
45. How to Login with Excel ?Write selenium Code. ?
46. How to verify dropdown values using Excel in selenium WebDriver. Write selenium Code. ?
47. How to run Multiple test cases from Testng.xml file. Write selenium Code. ?
48. For ex I have 3 columns from webTable .How to print the 2 column data from webtable. ?
49. Difference between selenium and qtp ?
50. Tell me about the brief introduction of selenium ?
51. Does selenium support mobile application testing ?
52. Can client server application can be automate through the selenium ?
53. which type of testing we are doing by using selenium ?
54. what are the limitations of selenium ide or selenium webdriver ?
55. How to identify webelement in selenium ?
56. when we will go for xpath in selenium ?
57. I want to run my application into firefox browser. How you handle it ?
58. what is the difference between id and name in selenium ?
59. How to handle dynamic objects in selenium ?
60. what are the locators available in selenium ?
61. what is the default timeout for selenium ?
62. When do we use implicit and explicit in selenium ?
63. How to handle ajax application in selenium webdriver ?
64. How to handle multiple Popup windows in selenium webdriver ?
65. Difference between findelement() and findelements() in selenium ?
66. How to handle the Expected alerts in webdriver ?
67. How to handle the UnExpected alerts in webdriver ?
68. My web page contain calendar, how to write script for calendar date selection ?
69. My checkbox would be in checked position, how can you say checkbox would be in check position ?
70. My login page contain captcha explain how to write script ?
71. How to run eclipse script from cmd prompt by Ant ?
72. How to execute same script in different browsers ?
73. what is isdisplayed in selenium ?
74. what is difference between iselementpresent and isdisplayed ?
75. Can you test flash images in selenium ?
76. How do you verify an object presented in multiple pages in selenium ?
77. How to select the dropdown values in selenium ?
78. Does selenium support https protocols ?
79. How to get the third column data from Table ?
80. Per day how many scripts your writing and executing ?
81. Tell me difficulty’s in your project faced by you ?
82. which driver implementation will allow headless mode ?
83. How to perform drag and drop operation in selenium webdriver ?
84. How many frameworks are there .which to use.how will you deside that ?

85. what is page object model in selenium ?
86. what framework your using can you explain the framework ?
87. what are the challenges did you faced while automating the application ?
88. Explain your Roles and Responsibilities in your project ?
89. How to connect selenium to database ?
90. which tool did you use for reporting ?
91. why did you choose selenium in your project where we are having so many tesing tools ?
92. what is difference between javascript and javaprogram ?
93. Why should we go for javascript in selenium ?
94. What is the alternate way to send text into textbox of webpage with out using sendKeys() method ?
95. If any button is hidden/disabled then how to click on button using selenium ?
96. send one empty mail from your official mail id ?
97. How to login into any site if its showing any authentication popup for user name and pass ?
98. How do you launch IE/chrome browser?
99. How to perform right click using WebDriver?
100. How do you simulate browser back , forward and refresh?
101. What is the difference between ‘/’ and ‘//’ ?
102. How do you handle https website in selenium
103. What is the use of AutoIt tool ?
104. How to count the number of checkboxes checked in selenium webdriver ? or How to select multiple check box and verify ?

TestNg :
———–

105. What is TestNg ?What is the use.?
106. What is Annotation ? How many Annotations are there in TestNg ?
107. what are the different assertions or check points used in your script?
108. Can we run group of test cases using TestNG ?
109. I have 50 testcases Here i want to execute only 3 test cases without using testng groups?
110. How to run only failure test cases in testNg ?
111. What is the difference between before method and before class ?
112. What is Data provider ?
113. What is return type of Data provider ?
114. Difference between junit and TestNg ?
115. How to handle ajax application in selenium webdriver ?
116. How to capture the bitmaps in selenium ?How to capture screenshot in selenium webdriver ?
117. How to read the methods/functions from xml/xls files ?
118. What is the difference between include and exclude in selenium ?
119. How to execute single selected method in testng ?
120. what is the difference between packages and classes in Testng?
121. what is the difference between verify and assert command ?
122. what we go for Assertions ?What is Assertions?
123. Tell me login page script in testng?
124. what is difference between @parameters and @data provider in testng ?
125. Is it possible to write to multiple test cases in single class ?
126. Which problems are faced in Testng ?
127. How to create test suites in testng ?
128. what is the library file of testng ?
129. How to read and write the data from Excel file using apache poi.
130. What Is TestNG And use of testNg?
131. What Is the usage of testng.xml file?
132. What is the command used inside the .bat file to run the testng.xml fille ?

133. What is the command line we have to write inside a .bat file to execute a selenium project when we are using testng ?
134. TestNg i have some tests line

@test1
@test2
@test3
@test4
@test5

I want to run my execution order is
@test5
@test2
@test1
@test4
@test3

What is a frame?

Frame is just like as a container where few elements can be grouped.

How to identify frame inside a webpage?

There are different ways to identify frame inside a webpage

Way 1:

  • Open webpage in a browser.

webelement in a webpage

  • Right click on webelement in a webpage

frame inside a webpage

Way 2:

  • Open webpage in a browser.
  • Right click on webelement in a webpage
  • Open source code(Html Code) of the webpage by clicking inspect element with firebug option see below image.

iframe source code

How to handle an element inside the frame?

There are 4 ways to handles frames in selenium webdriver.

Switch to frame by using index :

Method 1 :

Suppose if there is single frame in a webpage then we can switch to the iframe by using index.

Here is the sample code:

Syntax : driver.switchTo().frame(int index);

Example : driver.switchTo().frame(0);

Note : By default single frame index value ‘ 0’.That means when webpage has  only one frame then the index will be zero.

Method 2 :

Suppose if there are 3 frames in a webpage then we can switch to the iframe by using index.

Here is the sample code:

Syntax :

List<WebElement> framelist=driver.findElements(By.tagName(“iframe”));

driver.switchTo().frame(framelist.get(int index));

Example :

List<WebElement> framelist=driver.findElements(By.tagName(“iframe”));

//switchTo 1st frame by using index

driver.switchTo().frame(framelist.get(0));

  //switchTo 2nd frame by using index

driver.switchTo().frame(framelist.get(1));

//switchTo 3rd frame by using index

driver.switchTo().frame(framelist.get(2));

Switch to frame by using Id or Name :

We can also use Name and Id attributes of iframe  through which we can switch to iframes.

Here is the sample code:

Syntax 1:

driver.switchTo().frame(“Id of  the element”);

Html code :

iframe html code

                                                                                  Example : driver.switchTo().frame(“rightMenu”);

Syntax 2:

driver.switchTo().frame(“Name of  the element”);

Html code :

iframe html code

                                                                              Example : driver.switchTo().frame(“rightMenu”);

Switch to frame by using WebElement :

We can also switch to the frame using webelement.

Here is the sample code:

Syntax :

driver.switchTo().frame(WebElement);

Html code :

iframe html code

Example : driver.switchTo().frame(driver.findElement(By.name(“rightMenu”)));

How to get all the frames in a webpage ?

get all the frames in a webpage

Html code :

Open notepad and type the below Html code and save as frames.html

<html>

<body>

<iframe src=”http://www.seleniumhq.org/download/” width=”200″ height=”200″ name=”selenium”>

<p>Your browser does not support iframes.<p>

</iframe>

 

<iframe src=”http://127.0.0.1/orangehrm-2.5.0.2/login.php” width=”200″ height=”200″ name=”selenium”>

<p>Your browser does not support iframes.<p>

</iframe>

<br>

<iframe src=”http://testng.org/doc/index.html” width=”200″ height=”200″ name=”selenium”>

<p>Your browser does not support iframes.<p>

</iframe>

<br>

<a class=”gb_P” data-ved=”0EMIuCBMoAA” href=”https://mail.google.com/mail/?tab=wm” data-pid=”23″>Click on Gmail</a>

</body>

</html>

 

Example :

package seleniumProject;

import java.util.List;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

public class getTotalFrames {

public static void main(String[] args) {

//   Open Firefox Browser  

       WebDriver driver = new FirefoxDriver();

 //   Open AppURL In Browser

driver.get(“file:///C:/Users/Hanumanthu/Downloads/frames.html”);

 // count all the frames on a webpage

List<WebElement> total_frames=driver.findElements(By.tagName(“iframe”));

System.out.println(total_frames.size());

//close the current browser window

driver.close();

}

}

How to verify TestNg text inside 3rd frame?

verify TestNg text inside 3rd frame

Selenium Sample Code :

package seleniumProject;

import java.util.List;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

public class getTotalFrames {

public static void main(String[] args) {

   // Open Firefox Browser  

WebDriver driver = new FirefoxDriver();

//  Open AppURL In Browser

driver.get(“file:///C:/Users/Hanumanthu/Downloads/frames.html”);

 //count all the frames on a webpage

List<WebElement> total_frames=driver.findElements(By.tagName(“iframe”));

System.out.println(total_frames.size());

 //Switch to 3rd Frame by using Index

driver.switchTo().frame(total_frames.get(2));

  //Identify and get the text and store into testNg_text variable

String testNg_text=driver.findElement(By.xpath(“html/body/h2[1]”)).getText();

   //print the text from 3rd frame

System.out.println(testNg_text);

  //verify the text from 3rd frame

if(testNg_text.equals(“TestNG”))

{

System.out.println(“TestNG text verified successfully”);

}else

{

System.out.println(“TestNG text not verified successfully”);

}

 //How switch back to main window from inside any frame ?

driver.switchTo().defaultContent();

//Close the Firefox Browser

driver.close();

}

}

Note :

switch back to main window from inside any frame

1. Switch to 3rd Frame by using Index

Syntax :   driver.switchTo().frame(total_frames.get(index));

Example :   driver.switchTo().frame(total_frames.get(2));

2.Switch to 3rd  Frame by using Id

Syntax :   driver.switchTo().frame(“Id of the element”);

Example :   driver.switchTo().frame(“selenium”);

If no id then go for Name.

 3.Switch to 3rd  Frame by using Name

Syntax :   driver.switchTo().frame(“Name of the element”);

Example :   driver.switchTo().frame(“selenium”);

4.Switch to 3rd  Frame by using WebElement

Syntax :   driver.switchTo().frame(WebElement);

Example :   driver.switchTo().frame(driver.findElement(By.name(“selenium”);

 How switch back to main window from inside any frame ?

Syntax : driver.switchTo().defaultContent();

 How to handle frame in selenium webdriver using java

TestSteps:

Open Firefox Browser

Open AppURL In Browser

Get the Title of WebPage

Verify Title of WebPage

Enter the username

Enter the password

Clicking On Login Button

Identify and get  the Welcome selenium text

Verify  Welcome selenium text

Switch to frame

Handle DropDown in Selenium

  1.  How to print all the dropdown values
  2. How to Select the dropdown value inside a frame
  3. verify selected value from dropdown
  4. How to Verify dropdown values

Again switch back to main window from frame

Clicking On Logout Button

Close the Firefox Browser

Selenium Code :

package com.tests;

import java.util.List;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

importorg.openqa.selenium.support.ui.Select;

public class OrangeHRM_login {

public static void main(String[] args) throws Interrupted Exception {

// open the firefox browser

WebDriver driver = newFirefoxDriver();

// navigate the AppUrl

diver.get(“http://127.0.0.1/orangehrm-2.5.0.2/login.php”);

//Get the Title of WebPage

String title=driver.getTitle();

//print the title of the webpage

System.out.println(title);

//Verify Title of the WebPage

if (title.equals(“OrangeHRM – New Level of HR Management”)) {

System.out.println(“title is verified successfully”);

} else {

System.out.println(“title is not verified successfully”);

}

// Enter the username

  driver.findElement(By.name(“txtUserName”)).sendKeys(“selenium”);

// Enter the password

driver.findElement(By.name(“txtPassword”)).sendKeys(“selenium”);

// Clicking On Login Button

driver.findElement(By.name(“Submit”)).click();

// Identify and get  the Welcome selenium text and store into text variable

String text = driver.findElement(By.xpath(“//*[@id=’option-menu’]/li[1]”)).getText();

// Print the welcome selenium text

System.out.println(text);

//  To verify whether the welcome page successfully opened or not

if (text.equals(“Welcome selenium”)) {

System.out.println(“Welcome selenium is verified successfully”);

} else {

System.out.println(“Welcome selenium is not verified successfully”);

}

// Switch to Frame by ID

driver.switchTo().frame(“rightMenu”);

System.out.println(“****How to print all the dropdown values inside a frame****”);

Identify the dropdown

// Identify the dropdown

WebElement dropdown = driver.findElement(By.id(“loc_code”));

// Identify  dropdown values  and store into droplist  variable

List<WebElement> droplist = dropdown.findElements(By.tagName(“option”));

// How to print all the dropdown values

for (inti = 0; i<droplist.size(); i++) {

System.out.println(droplist.get(i).getText());

}

System.out.println(“*****How to Select the dropdown value inside a frame*****”);

Select the dropdown value inside a frame

/*

                    If u want to select the dropdown value then we need to create the select object for that dropdown

                    */

Select s = new Select(dropdown);

// Select the dropdown value by using index

s.selectByIndex(2);

//s.selectByVisibleText(“Emp. First Name”);

//s.selectByValue(“1”);

System.out.println(“****verify selected value from dropdown inside a frame *****”);

verify selected value from dropdown inside a frame

//get the selected value and store into selected_value variable

String  selected_value=s.getFirstSelectedOption().getText();

//print selected value

System.out.println(“selected_value  :”+selected_value);

//verify selected value from dropdown

if (selected_value.equals(“Emp. First Name”)) {

System.out.println(“selected value  verified successfully”);

} else {

System.out.println(“selected value not verified successfully”);

}

// How switch back to main window from inside any frame

driver.switchTo().defaultContent();

// Clicking On Logout Button

driver.findElement(By.xpath(“//*[@id=’option-menu’]/li[3]/a”)).click();

// Close the Firefox Browser

driver.close();

}

}

 

 

Kotlin For Android Developers

Kotlin For Android Developers

Kotlin For Android Developers

Kotlin is a new programming language from JetBrains, the maker of the world’s best IDEs. Now Kotlin supported by Google For Android.
 
Kotlin comes from industry, not academia. It solves problems faced by working programmers today. As an example, the type system helps you avoid null pointer exceptions. Research languages tend to not have null at all.

1. Why Kotlin

 
1.1 Java Interoperability
 
Kotlin language is inter-operable with java. It means we can user previous java project with new kotlin classes also and all java frameworks are still available. We have a one click java to kotlin converters also.
 
1.2 Familiar syntax
 
Kotlin Language syntax is very familiar to any programing language who came from OOP domine. There are some differences compare to Java such as val, var
 
Class Example{
 
val a:String= “Kosmik” //val means unmodifiable
 
Var i:int=1 // var means modifiable
 
}
 
Fun hellworld(){
 
Val str=”hello”
 
print(“$str World”)
 
}
 
1.3 String Interpolation
 
It’s as if a smarter and more readable version of Java’s String.format() built into the Kotlin language
 
var x=4
 
var y=3
 
print(“sum of $x and $y is ${x+y}”) //sum of 4 and 7 is 11
 
1.4 Open Source
 
It is open source under apache 2.0
 
1.5 Compatibility
 
Kotlin is fully compatible with JDK6 and kotlin applications can run on older android devices also
 
1.6 Performance
 
Kotlin application will run fast as an equal to java
 
1.7 Support
 
Kotlin is fully supported from Android Studio 3.0
 
1.8 Some Syntaxes
  1. No more semicolons ;
  2. Variable declaration is different in kotlin like var is mutable and val is immutable
  3. Functions in kotlin (methods)

fun sum (x: Int ,y: Int): Int{

return x+y

}

  1. when function

Now switch changed into when a condition, which is very easy to understand  like below example

when (x) {

   1 -> print(“x is 1”)

   2 -> print(“x is 2”)

   3, 4 -> print(“x is 3 or 4”)

   in 5..10 -> print(“x is 5, 6, 7, 8, 9, or 10”)

   else -> print(“x is out of range”)

}

6.creating a class in kotlin

val rectangle = Rectangle(5.0, 2.0) //no ‘new’ keyword required

val triangle = Triangle(3.0, 4.0, 5.0)

Android Training in Hyderabad

kosmik provides Android training in Hyderabad, we are providing lab facilities with complete real time training & 100% job assistance will be there

Steps to configure Selenium WebDriver with java to develop test scripts

Pre-conditions: We need below files

Step 1: Download and Install JDK 8

Follow below URL

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Select Accept License Agreement radio button

Java SE Development Kit 8

Choose version to download: Windows 86 or x64 based on your OS (jdk-8-windows-i586.exe and jdk-8-windows-x64.exe)

  • wait until complete download.
  • copy downloaded file and paste in personal folder.
  • click on setup to start installation.
  • click on next until installation will go to end
  • click on close.
  • Restart Computer.

Note :

After completion of JDK installation tester can create environment variable for JAVA_HOME in your windows system by following below navigation.

  • Click on start
  • Right click on my computer
  • Click on properties
  • Click on Advanced system setting
  • Select Advanced tab
  • Click on Environment variable button
  • Go to user variables
  • click on New button
  • Type JAVA_HOME and provide path of JDK folder
  • click on ok

Follow below image

Environment variable button

  • Go to system variable
  • Select path
  • click on Edit button
  • Add path of JDK bin folder followed by semicolon(😉 at the end of existing path value
  • Click on ok
  • Click on ok

Follow below image

Environment variables

How to verify java successfully installed or not into your local system

  • Open the command prompt.
  • Run command “java -version”

 

It should show your installed java version detail as shown in above image. That means java is installed successfully into your local system and you are ready to use it.

Step 2: Download and launch Eclipse IDE

  1. IDE stands for Intigrated Development Environment. Eclipse Ide is useful to write our test scripts in java or java based tools like selenium.
  1. We need to follow below URL to download and launch Eclipse Ide

 

http://www.eclipse.org/downloads/packages/release/Mars/2

Eclipse Mars 2 Packages

 

Download the Eclipse Mars, you can choose version Windows 32 bit or 64 bit based on your OS

  • wait until complete download.
  • copy downloaded file and paste into personal folder and extract
  • click on Eclipse folder
  • Here click on ‘eclipse.exe’ file directly. Here no need to install eclipse into your local system.

Step 3: Download Selenium WebDriver Jar Files.

After completion of eclipse Ide launching with the creation of project, package, and class with main(), we need to download selenium webdriver jar file.

Follow the below steps :

  • Go to google search
  • Enter seleniumhq then search it
  • Click on first link(https://www.seleniumhq.org/download/)
  • Click on download
  • Scroll to Selenium Client & WebDriver Language Bindings
  • Click on download for java based selenium webdriver

Selenium Client & WebDriver Language Bindings

  • wait until complete download.
  • copy downloaded jar file and paste into personal folder and extract

Step 4: Associate selenium webdriver with eclipse Ide.

  • click on ‘eclipse.exe’ to start eclipse
  • First time when you start eclipse software application, it will ask you to select your workspace where your work will be stored as shown in bellow image.

Workspace Launcher

Choose a workspace folder name as D:\workspace and click on ok button .Here You can change the workspace location from ‘Switch Workspace’ under ‘file’ menu of eclipse.

Create new project

  • Go to File
  • New
  • Go to Java Project and give your project name ‘SeleniumProject’
  • Click on finish button.

Create new package

  • Right click on source folder(src)
  • New
  • Package
  • give the package name ‘SeleniumTests’
  • Click on finish button.

Create New Class

  • Right click on package ‘SeleniumTests’
  • New Class
  • give the class name ‘myTestLogin’
  • click on Finish button.

Add external jars for that project

  • Right click on project ‘SeleniumProject’
  • go to Java build path
  • configure build path
  • >select Libraries
  • Click on add external JARs button
  • Then go your jar file folder path location
  • select both .jar files from D:\selenium-java 3.12.0.
  • click on open button
  • Click on add external JARs button
  • Then go your jar file folder path location
  • select all .jar files from D:\selenium-java 3.11.0\libs
  • click on open button
  • click on ok button

Steps to Download and Install firebug Add-on.

Follow my below url to install Fire Bug

https://addons.mozilla.org/en-US/firefox/addon/firebug/

Click on Add to Firefox button

Click on Install button

After install FireBug then go to

Tools > Web Developer > Firebug > Open Firebug (or)you can use shortcut key ‘F12’

 

After open the firebug. Right-click on field or element in your application then click on inspect element with firebug option.

In html code take either id(or)name(or)className etc. from highlighted section.

See below image

Hospital Management System

Note: Here no need to restart your Firefox after installing Firebug Add-On

Steps to Download and Install firepath Add-on.

Follow my below url to install Firepath add-on

https://addons.mozilla.org/en-US/firefox/addon/firepath/

Click on Add to Firefox button

FirePath By pierre Tholence

Click on Install button

Click on Restart Now

After install firepath then go to

Tools > Web Developer > Firebug > Open Firebug (or)you can use shortcut key ‘F12’

You could find ‘FirePath’ as shown below image

 

Selenium WebDriver First Program :

TestSteps:

  • Open the firefox browser
  • Navigate the application url
  • Get the Title of the WebPage
  • Print the title of the webpage
  • Verify Title of the WebPage
  • Enter the username
  • Enter the password
  • Clicking On Login Button
  • Identify and get the Dashboard Text
  • Print the Dashboard Text
  • To verify whether the welcome page successfully opened or not
  • Clicking On Logout Button
  • Close the current Firefox Browser

Selenium Code :

package seleniumProject;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class SampleClass {

public static void main(String[] args) throws Interrupted Exception {

// open the firefox browser

WebDriver driver = new FirefoxDriver();

// navigate the application url

driver.get(“http://www.kosmiktechnologies.com/se leniumLiveProject/eKart/admin/”);

//Get the Title of the WebPage

String title=driver.getTitle();

//print the title of the webpage

System.out.println(title);

//Verify Title of the WebPage

if (title.equals(“Administration”))

{

System.out.println(“title verifiedsuccessfully”);

} else {

System.out.println(“title not verified successfully”);

}

// Enter the username

driver.findElement(By.name(“username”)).sendKeys (“Kadmin”);

// Enter the password

driver.findElement(By.name(“password”)).sendKeys (“K@admin”);

// Clicking On Login Button

driver.findElement(By.xpath(“//*[@id=’content’]/ div/div/div/div/div[2]/form/div[3]/button”)).cli ck();

// Identify and get the Dashboard Text

String text = driver.findElement(By.xpath(“//*[@id=’content’]/div[1]/div/h1”)).getText();

// Print the Dashboard Text

System.out.println(text);

// To verify whether the welcome page successfully opened or not

if (text.equals(“Dashboard”))

{

System.out.println(“Welcome pageverified successfully”);

} else {

System.out.println(“Welcome page not verified successfully”);

}

// Clicking On Logout Button

driver.findElement(By.xpath(“//*[@id=’header’]/u l/li[3]/a”)).click();

//Close the current Firefox Browser driver.close();

}

}

SELENIUM | BROWSER COMMANDS :

1.get() : This will be used to navigate the application url

Syntax : driver.get(“appURL”);

2.getTitle() : This will be used to get the title of the current Webpage.

Syntax : driver.getTitle();

3.findElement() : By using this we can identify single webelement On a webpage.

Ex: Button, checkbox, radio button etc.

Syntax : driver.findElement(By.Locator(“Locator-Value”));

4.findElements() : By using this we can identify list of webelements On a webpage.

Ex :

  1. Suppose if you want to identify dropdown values at a time then we use findElements method.
  2. Suppose if you want to identify list of frames in a webpage then we use findElements method.
  3. Suppose if you want to identify list of links in a webpage then we use findElements method.

Syntax :

List<WebElement> total_Links = driver.findElements(By.tagName(“a”));

5.sendKeys() : If you want to give the value to the input field(textbox,text area) then we use sendkeys method.

Syntax :

driver.findElement(By.locator(“locator-value”)).sendKeys(“text”);

6.getText() : If you want to get the particular text in a webpage then we use getText method.

Syntax :

String PageText=driver.findElement(By.Locator(“Locator-value”)).getText();

7.click() :Is there any click operation in your application then we use click().

Syntax :

driver.findElement(By.Locator(“Locator-value”)).click();

8.close() : This will be used to close the current browser window.

Syntax : driver.close();

Important Interview Questions :

1. How to Identify WebElement in selenium webdriver?

A )By using firebug and firepath we can Identify

WebElement.

2. Can we use firebug and firepath for chrome and Ie?

No,

1.Here firebug and firepath these two add-ons only for firefox.

2.Suppose if u want to identify the WebElement In chrome and ie here no need to install firebug and firepath. Becoz chrome and ie have its won developer tool to identify the web element.

3. What is the default package of selenium?

  1. org.openqa.selenium

4. What is the difference between findElement() and findElements()?Find ElementsfindElement() :

By using this we can identify single webelement On a webpage.

Ex : Button, checkbox,radio button etc.

Syntax : driver.findElement(By.Locator(“Locator-Value”));

TestSteps :

  • open the firefox browser
  • navigate the application url Enter the username
  • Close the current Firefox Browser

Selenium Program :

package seleniumProject;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class findElementMethod {

public static void main(String[] args) throws Interrupted Exception {

// open the firefox browser

WebDriver driver = new FirefoxDriver();

// navigate the application url

driver.get(“http://www.kosmiktechnologies.com/se leniumLiveProject/eKart/admin/”);

// Enter the username

driver.findElement(By.name(“username”)).sendKeys (“Kadmin”);

//Close the current Firefox Browser

driver.close()

}

}

findElements() : By using this we can identify list of webelements On a webpage.

Ex :

  • Suppose if you want to identify dropdown values at a time then we use findElements method.
  • Suppose if you want to identify list of frames in a webpage then we use findElements method.
  • Suppose if you want to identify list of links in a webpage then we use findElements method.

Syntax :

List<WebElement> total_Links = driver.findElements(By.tagName(“a”));

TestSteps :

  • open the firefox browser
  • navigate the application url
  • Identify all the links and store into total_Links variable Print the total Links on a webpage
  • Close the current Firefox Browser

Selenium Program :

package seleniumProject;

import java.util.List;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

public class findElementsMethod {

public static void main(String[] args) throws InterruptedException {

// open the firefox browser

WebDriver driver = new FirefoxDriver();

// navigate the application url

driver.get(“http://www.kosmiktechnologies.com/se leniumLiveProject/eKart/admin/”);

//Identify all the links and store into total_Links variable

List<WebElement> total_Links = driver.findElements(By.tagName(“a”));

//Print the total Links on a webpage

System.out.println(total_Links.size());

//Close the current Firefox Browser

driver.close();

}

}

5.How to verify particular text on a webpage using selenium webdriver?  (Or) How to verify successful message on a webpage using selenium webdriver?

TestSteps :

  • open the firefox browser
  • navigate the application url Enter the username
  • Enter the password
  • Clicking On Login Button
  • Identify and get the Dashboard Text Print the Dashboard Text
  • To verify whether the welcome page successfully opened or not Clicking On Logout Button
  • Close the current Firefox Browser

Selenium Program :

package seleniumProject;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class SampleClass {

public static void main(String[] args) throws Interrupted Exception {

// open the firefox browser

WebDriver driver = new FirefoxDriver();

// navigate the application url

driver.get(“http://www.kosmiktechnologies.com/se leniumLiveProject/eKart/admin/”);

// Enter the username

driver.findElement(By.name(“username”)).sendKeys (“Kadmin”);

// Enter the password

driver.findElement(By.name(“password”)).sendKeys (“K@admin”);

// Clicking On Login Button

driver.findElement(By.xpath(“//*[@id=’content’]/

div/div/div/div/div[2]/form/div[3]/button”)).click();

// Identify and get the Dashboard Text

String text =

driver.findElement(By.xpath(“//*[@id=’content’]/ div[1]/div/h1”)).getText();

// Print the Dashboard Text

System.out.println(text);

//To verify whether the welcome page successfully opened or not

if (text.equals(“Dashboard”))

{

System.out.println(“Text matched”);

} else {

System.out.println(“Text notmatched”);

}

// Clicking On Logout Button

driver.findElement(By.xpath(“//*[@id=’header’]/u l/li[3]/a”)).click();

//Close the current Firefox Browser

driver.close();

}

}

Control statements :

Syntax :

If(Actual_value.equals(Expected_value))

{

//Execute the code if condition is true

}else

{

//Execute the code if condition is false

}

Actual_value : Take the text from Testing Application.

Expected_value : client requirement

6.Difference between close() and quit() in selenium webdriver ?
Driver.close() :

By using this we can close the current browser window.

I.e Single window on which driver is having focus that will be closed only

Difference between close() and quit() in selenium webdriver

Driver.quit() : Every associated browser will be closed

I.e closed all the windows opened by the driver.

7. What is the purpose of public static void main() in java ?

public :

Since main() should be available to JVM. It should be declared as public.I f we don’t use main() as a public then it doesn’t make itself available to JVM and JVM cannot execute it.

Static :

We should be call the main() without creating an object, such methods are called static methods and we should be declared as static.

Void :

If main() it does not written any value then you have to put void(no value) before the main().

main():

If main() is not written in the java program then JVM will not execute the program.main() is the starting point for JVM to start execution of java.

What are the pre-requisites to run the selenium web driver?
  1. JDK 8
  1. Eclipse IDE
  1. Selenium JAR file
  1. Testing Application
  1. Browser (Firefox 53.0)
  1. Firebug
  1. Firepath

How to handle frame in selenium webdriver using java

Selenium Training in Hyderabad

kosmik technologies is the best institute for selenium training in Hyderabad. we offer classroom and selenium online training courses by certified faculty. Selenium is an open source tool for web application testing. This tool primarily developed in JavaScript and browser technologies and hence supports all major browsers on all the platforms. Selenium is one of the best tool available in the market for a web application.