Anda di halaman 1dari 27

SDET(Software Development Engineering in Testing)

SDET is responsible to test a software via scripts/programms running

Manual Testing V/S Automation Testing

Manual testing is to test a software without using any tools whereas


SDET can test a software by using testing tools like Selenium

Need for Automation:

Pic 1

From the above process SDET can automate previously failed test cases
and related passed test cases for future real and regression testing
on modified sprint/s/w

Note: Sometimes SDET will go to automation due to


1)to save time
2)to decrease complexity

Functionla testing is to save time where as performance testing to


decrease complexity

Availability of testing tools

Fucntional testing is to save time

Selenium, Qtp, winrunner, test complete, sahi

Peformance testing

Load runner, Jmeter and webload test to decrease complexity

Types of Softwares:

1)computer based
a)1-tier (S/w have screens only)
b)2-tier(S/w have screens with DB)
c)3-tier(Website)
d)n-tier(Webservice)

2)Mobile based
a)native app
b)hybrid app
c)website

Selenium WebDriver

1)Developed by Simon Stewart


2)open source
3)Available in java, c#.net, php, perl, python, and javascript
4)Java based selenium webdriver is now famous to automate functional
testing on website in any computer because java is platform
independent
Selenium webdriver 3.0 is available from august 2016

Configure Selenium webdriver in tester computer

Pic 2
Step1: Download and install jdk 8

->Start
->Right click on computer
?>properties
->check system type which is 32-bit or 64-bit
->close properties
?>Go to google site
->Enter jdk 8 download
?>click search
->Go to oracle.com site and
->Accept liscence agreement
->click jdk download with respect to OS and bit size
->paste the download in personal folder
->double click on that download
->click next until finish
->go to c:drive and copy path of jdk folder
(c:/program files/java/jdk1.8)
->Right click on computer
->properties
->Advanced system settings
->Environment variables
?>click new in system variables

Name JAVA_HOME
Value c:/program files/java/jdk1.8

->select path variable


->Edit
->path ; c:/program files/java/jdk1.8/bin;
->ok
->ok
->ok

Step2: Download and launch Eclipse IDE

->Go to google site


->enter eclipse juno download(Eclipse ide for java ee developers)
->go to eclipse.org website
->click on Eclipse ide for java ee developers w.r.to bit size and OS
->paste the download in personal folder.
->Extract the download
->open eclipse folder and create shortcut to eclipse on desktop

Note1:
1)Double click on eclipse icon and it will ask the workspace folder
2)Browse path of personal folder as workspace
3)select do not ask again checkbox
4)click ok
5)close welcome screen in eclipse ide

Note2: How to create a project in eclipse


->File menu in eclipse
->New
->other
->Java project
->Next
->Enter a name to project which is single word and should be in lower
case
->Finish
->Right click on that project
?>Properties
->Java build path
->libraries
->Remove existing jre
->add library
->JRE system library
->click ok
->click yes to affect changes
->java compiler
->select latest version(1.7)
->apply
->ok

Note3: How to create a package


->Right click o project
->New
->Package
->Enter a name to package which is single word and should be in lower
case
->click finish

Note4: How to create a class with main method


->File menu
->New
->class
->Enter a name to class with Init cap(Initial capital letter) as
single word.
->Select checkbox public static void main and unselect inherited
methods
->Finish

Step3: Download and associate Selenium jars

Selenium webdriver is available as jars


each jar is having classes with methods/operations.
we are using these classes in main() method

->Launch seleniumhq.org site in google


->click download
->go to selenium webdriver java
->paste the download in personal folder
->extract the download
->right click on project in eclipse ide
->properties
->java build path
->libraries
->browse path of selenium jars in personal folder(lib folder inside
jars and outside jar)
->ok

Step4: Integrating Eclipse IDE and browser


Pic 3
From the above diagram, browser driver is useful to integrate eclipse
ide and browser window. These drivers are availabe in seleniumhq.org
website. From the site we need to download geckodriver.exe,
Iedriverserver.exe, chromedriver.exe and operadriver.exe for firefox,
IE, chrome and opera browsers respectively.

Eg: Selenium webdriver code for chrome browser


System.setPropert(“webdriver.chrome.driver”,”chromedriver.exe”);
WebDriver driver=new ChromeDriver();

Step5: Writing test script using Selenium webdriver

1)Selenium webdriver jars are having classes

2)Every class is having methods to perform operations on webpage


elements

Methods in Webdriver class:

get(): we can use this method to get a website in browser by


specifying a url
syntax:

WebDriver driver=new ChromeDriver();


driver.get("url")

close(): we can use this method to close active browser window

driver.close()

Test scenario1:
1)Launch google website using chrome browser
2)wait for few seconds
3)close site

Test script:
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://www.google.co.in/");
Thread.sleep(5000);
driver.close();

quit(): we can use this metghod to close active browser and other
related windows.
syntax: driver.quit()
object of webdriver class method

getTitle(): we can use this method to get the title of active browser
window

Test Scenario2:
1)Launch google site using chrome browser
2)wait for few seconds
3)get title of site
4)close site

System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver=new ChromeDriver();
//launch site
driver.get("http://www.google.co.in/");
Thread.sleep(5000);
String x=driver.getTitle();
System.out.println(x);
driver.close();

getCurrenturl(): we can use this method to get url of active browser


window page
Test scenario3:
1)Launch gmail site using chrome browser
2)wait for few seconds
3)get current url and check that url contains https or not
http(hyper text transfer protocol)
4)close site

System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://www.gmail.com/");
Thread.sleep(5000);
String x=driver.getCurrentUrl();
if(x.contains("https"))
{
System.out.println("securable site");
}
else
{
System.out.println("not a securab;le site");
}
driver.close();

getPagesource(): we can use this method to get the html source code
of current active window

findElement(): we can use this method to locate an element in webpage


to perform an operation.

Syntax:
Pic 4
Test scenario:

1)launch mercury tours site using chrome browser


2)click on registration link
3)fill fields
4)click submit
5)close site

System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver=new ChromeDriver();
//launch site
driver.get("http://newtours.demoaut.com/");
Thread.sleep(5000);
driver.findElement(By.linkText("REGISTER")).click();
Thread.sleep(3000);
driver.findElement(By.name("firstName")).sendKeys("abc");
Thread.sleep(1000);
driver.findElement(By.name("lastName")).sendKeys("bcd");
Thread.sleep(1000);

driver.findElement(By.name("phone")).sendKeys("1234567790");
Thread.sleep(1000);

driver.findElement(By.id("userName")).sendKeys("abc@gmail.com");
Thread.sleep(1000);
driver.findElement(By.name("address1")).sendKeys("no 10");
Thread.sleep(1000);

driver.findElement(By.name("address2")).sendKeys("kukatpally");
Thread.sleep(1000);
driver.findElement(By.name("city")).sendKeys("hyderabad");
Thread.sleep(1000);
driver.findElement(By.name("state")).sendKeys("TS");
Thread.sleep(1000);

driver.findElement(By.name("postalCode")).sendKeys("500087");
Thread.sleep(1000);
Select s=new
Select(driver.findElement(By.name("country")));
s.selectByVisibleText("INDIA");
Thread.sleep(1000);
driver.findElement(By.id("email")).sendKeys("abcd");
Thread.sleep(1000);

driver.findElement(By.name("password")).sendKeys("abc@1234");
Thread.sleep(1000);

driver.findElement(By.name("confirmPassword")).sendKeys("abc@1234");
Thread.sleep(1000);
driver.findElement(By.name("register")).click();
Thread.sleep(5000);
driver.close();

install firebug and firepath in firefox browser

Click(): we can use this method to perform click operation on an


element in webpage

Syntax: driver.findElement(locator).click();

sendKeys(): we can use this method to send keyboard keys(data keys


and functional keys) to an element in webpage.

Syntax: driver.findElement(By.name("Email")).sendKeys("xxxx");
driver.findElement(By.name("signIn)).click();

or

driver.findElement(By.name("Email")).sendKeys("xxx", Keys.TAB,
Keys.ENTER)

From the above example, Keys class is useful to represent functional


keys in keyboard. To specify a combination of keys we can use
Keys.chord() method

Eg: driver.findElement(locator).sendKeys("aaaa",
Keys.chord(Keys.CONTROL, "a"));

Enter Amber in located element and select all to that element.

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


{
System.setProperty("webdriver.chrome.driver",
"chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://www.gmail.com/");
Thread.sleep(5000);

driver.findElement(By.id("identifierId")).sendKeys("aaaa@gmail.com",
Keys.chord(Keys.CONTROL,"a"));
Thread.sleep(5000);
driver.close();
}

getAttribute():
getCssvalue():

we can use these methods to get the values of cosing attributes and
style attributes of ekement in webpage

tagName
<input id="identifierId" class="whsOnd zHQkBf" type="email" data-
initial-value="" data-initial-dir="ltr" dir="ltr" name="identifier"
aria-label="Email or phone" tabindex="0" spellcheck="false"
autocomplete="username" jsname="YPqjbf"/>

coding attributes like id, class, data-initial-value, sir, name,


aria-label, tabindex, spellcheck, jsname and autocomplete

In general style attributes of an element are


1)color, font, border style

getText(): we can use this method to get the visible text of an


elememt in webpage

Syntax:

String x=driver.findElement(By.name("Emaik")).getText();

getTagName():
we can use this method to get the tagname of an located element in
webpage

String x=driver.findElement(locator).getTagName();

Eg: Tags in html are


<a>, <input>, <b>, <i>, <table>, <td>, <tr>, <img>, <button>.....etc

findElements(): we can use this method to collect all multiple


similar elements in webpage.

Eg: click third link in webpage.

List <WebElement> l=driver.findElements(By.tagName("a"));


l.get(2).click();

Eg2: click last link in webpage


List <WebElement> l=driver.findElements(By.tagName("a"));
l.get(l.size()-1).click();

Eg3: select India in 4th dropdown in page.

List <WebElement> l=driver.findElements(By.tagName("select"));


Select s=new Select(l.get(3));
s.selectByVisibleText("India")

Eg4: click 3rd image in 4th column in 3rd row in 2nd table in page.

List <WebElement> l1=driver.findElements(By.tagName("table"));


List <WebElement> l2=l1.get(1).findElements(By.tagName("tr"));
List <WebElement> l3=l2.get(2).findElements(By.tagName("td"));
List <WebElement> l4=l3.get(3).findElements(By.tagName("img"));
l4.get(2).click();

Eg5: Select India in 3rd dropdown in 4th column in 4th row in 2nd
table in page

List <WebElement> l1=driver.findElements(By.tagName("table"));


List <WebElement> l2=l1.get(1).findElements(By.tagName("tr"));
List <WebElement> l3=l2.get(3).findElements(By.tagName("td"));
List <WebElement> l4=l3.get(3).findElements(By.tagName("select"));
Select s=new Select(l4.get(2));
s.selectByVisbileText("India");

Note1: While automating different type of elements in webpages, we


need to get awareness on hrml tags like shown below.

tagName in Html purpose


<select> to develop dropdowns
<a> to develop links
<img> to develop images
<table> to develop table
<tr> to develop row in a table
<td> to develop column in row in table
<br> to develop break
<span> to develop plain text
<div> to develop ajax controls
<button> to develop buttons
<iframe> to develop frame

<input> to develop multiple type of elements like


button
checkbox
color
date
datetime
datetime-local
email
file
hidden
image
month
number
password
radio
range
reset
search
submit
tel
text
time
url
week

Eg6: collect all radio buttons in page

List <WebElement> l=driver.findElements(By.tagName("input"));


int c=0;
for(int i=0;i<l.size();i++)
{
String x=l.get(i).getAttribute("type");
if(x.equals("radio")
{
c=c+1
}
}
System.out.println(c);

OR

List <WebElement>
l=driver.findElements(By.xpath("//input[@type='radio']"));
int c=l.size(); //100
System.out.println(c); //100

"c" specifies count of radio buttons in page


Eg7: count no of buttons which are developed using button tag and
input tag in html

List <WebElement> l1=driver.findElements(By.tagName("button"));

List <WebElement>
l2=driver.findElements(By.xpath("//input[@type='button']));

int c=l1.size()+l2.size();

System.out.println(c);

Eg8: count no. of images in a webpage which are developed using image
tag and input tag

Eg9: Count no of textboxes and password boxes in webpage, which are


developed using input tag

List <WebElement>
l1=driver.findElements(By.xpath("//input[@type='text']"));

List <WebElement>
l2=driver.findElements(By.xpath("//input[@type='password']"));

int c=l1.size()+l2.size();
OR
List <WebElement>
l=driver.findElements(By.xpath("//input[@type='text'
@type='password']"));
int c=l.size();

switchTo.frame(): we can use this method to change the focus of


webdriver class object from active page to specified frame in that
page.

driver.switchTo.frame("name"/Index);

Note1: In general, iframe tag is having name attribute. if there is


no name to any frame then we can use index.

Note2: while assigning index to frames in a page, we need to follow


below type of indexing.

switchTo().parentFrame(): we can use thiss method to change focus


from current frame to parent frame

switchTo().defaultContent(): we can use this method to change the


focus from current frame to page.
Eg1:

Pic 5

driver.findElement(By.name("username")).sendKeys("xxx");
driver.switchTo().frame("frame1");
driver.findElement(By.id("password")).sendKeys("xx");
driver.switchTo().defaultContent();
driver.findElement(By.name("ok")).click();

Eg2:
Pic 6
driver.switchTo().frame("frame1");
driver.findElement(By.id("uname")).sendKeys("xxx");
driver.switchTo().frame("frame2");
driver.findElement("password")).sendKeys("xxx");
driver.switchTo().parentFrame();
driver.findElement(By.id("age")).sendKeys("xxx");
driver.switchTo().defaultContent();
driver.findElement(By.id("ok")).click();

Eg3:
Pic 7
driver.switchTo().frame("frame1");
driver.findElement(By.id("uname")).sendKeys("xxx");
driver.switchTo().defaultContent();

driver.switchTo().frame("frame2");
driver.findElement(By.id("password")).sendKeys("xxx");
driver.switchTo().defaultContent();

driver.findElement(By.id("ok")).click();

Test Scenario:
Launch guru99 website
click on jmeter made easy image(use frames)
close site

System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://demo.guru99.com/test/guru99home/");
Thread.sleep(5000);
driver.switchTo().frame("a077aa5e");

driver.findElement(By.xpath("//img[@src='Jmeter720.png']")).click();
Thread.sleep(3000);
driver.close();

switchTo().alert():

In websites alerts are of 2 types such as Webalert and window alert.


we can use this method to handle web alerts in websites.
Pic 8

Webalerts can be handled by Selenium


Window alerts will be handled by Java Robot/Sikuli.

Eg1:
Pic 9

driver.switchTo().alert().accept();

or

driver.switchTo().alert().dismiss();

Eg2:
Pic 10

driver.switchTo().alert().accept();//ok

driver.switchTo().alert().dismiss();//cancel

Eg3:
Pic 11

String x=driver.switchTo().alert().getText();

System.out.println(x)
driver.switchTo().alert().accept();

Eg4:

Pic 12

driver.switchTo().alert().sendKeys("xxx", Keys.TAB, "xxx");


driver.switchTo().alert().accept();

Eg5:
Pic 13
driver.switchTo().alert().sendKeys(Keys.DOWN, Keys.DOWN, Keys.ENETR)
driver.switchTo().alert().accept();

switchTo().window():
we can use this method to change the focus of webdriver class object
from current window page to new browser window page.

Syntax: driver.switchTo().window("windowid");

Eg: ArrayList <String> l=new ArrayList


<String>(driver.getWindowHandles)

Test Scenario:
Test Scenario:
1)Launch alibaba site
2)click on one request multiple quotes button
3)close one request multiple quotes page browser window
4)close site

System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.alibaba.com/?
src=sem_ggl&cmpgn=70223922&adgrp=2741927802&fditm=&tgt=kwd-
14739453&locintrst=&locphyscl=9062134&mtchtyp=e&ntwrk=g&device=c&dvcmdl=&cr
eative=232587960886&plcmnt=&plcmntcat=&p1=&p2=&aceid=&position=1t1&gclid=EA
IaIQobChMIkKLQtqfl3gIVxoyPCh2rdAauEAAYASAAEgLjuvD_BwE");
Thread.sleep(10000);
driver.findElement(By.xpath("//a[contains(text(),'One Request,
Multiple Quotes')]")).click();
Thread.sleep(10000);
ArrayList <String> l=new
ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(l.get(1));
driver.close();
driver.switchTo().window(l.get(0));
driver.close();

getWindowHandle(): we can use this method to get window id of current


active browser window
Syntax:
String x=driver.getWindowHandle();
System.out.println(x)

getWindowHandles(): we can use this method to get window id of


current browser windows on desktop.

Syntax:
ArrayList <String> l=new ArrayList<String>driver.getWindowHandles();

class in java util package

manage().window().maximize():
we can use this mehtod to maximize the active browser window.

syntax: driver.manage().window().maximize();

manage().deleteAllCookies():
Cookies is a server side programs and running on client system to
share client system to server.

we can use this method to delete all existing cookies in client


system

manage().getCookies().size():

we can use this method to get count of existing cookies. In general,


related cookies are loaded while getting corresponding website pages.

navigate().to():
navigate().back():
navigate().forward():
navigate().refresh():
--------------------
we can use these methods to manipulate activer browser window

Types of xpaths:

xpath is an address to locate an element in webpage. In general,


xpath topic is related to xml language(Extensible markup language).
But in selenium webdriver, we can treate html (HyperText Markup
language) source code of webpage as an xml file to locate element
using xpath. In selenium webdriver coding, we can go to xpath to
locate an element in webpage. when:

-->absolute xpath is an address to locate an element in webpage by


writing tags from html/body to corresponding tag.

Eg: html/body/div[4]/div/div[1]/div/a/img

--> Relative xpath is useful to us to locate dynamically changing


elements also in webpages. In general relative xpath is syntax bsed
xpath. Firepath in firefox, xpath helper in chrome...can help us to
know correctness of relative xpath

Syntax1: //tagName[@attriibute='value']

//input[@type='radio']

Syntax2:
//tagName[@attribute='value'][@attribute='value']

//input[@type='button'][@value='Register Here']

Syntax3:

//tagName[@attribute='value' or @attribute='value']

//input[@type='button' or @value='Register Here']

Syntax4:
if ant element is of 3 matching nodes then we want to use 2nd element
then we will use the below syntax.

(//tagName[@attriibute='value'])[Index]
1-based(index starts from 1 here)

(//input[@type='radio'])[2]

Syntax5:

//*[@attribute='value']

* means any tag. it matches all elements in page.

//*[@type='radio']

Syntax6:

//*[start-with(@attribute, 'starting value')]


Eg: raja ram mohan roy

//*[start-with(@name, 'raja')]

Syntax7:

//*[contains(@attribute, 'value')]

Eg: sachin tendulkar

//*[contains(@name, 'Ten')]

Syntax8:

(//*[@attribute='value'])[last()]

locate last element in matched elements

(//*[@attribute='value'])[last()-2]

locate 2nd element from last in matched elements

Syntax9:

//*[@attribute='value']/div//input
relative xpath to neighbour absolute xpath to target element
element from neighbouring element
facebook appllication 1,00,000 users

1,00,000 people
1,00,000 chairs
1,00,000 tables
1,00,000 laptops
1,00,000 room capacity

Anda mungkin juga menyukai