Monday, March 28, 2016

Selenium JAVA and RUBY Web Objects Methods

I've list out the methods available in Selenium framework. I've defined methods in JAVA and also 
a corresponding method in RUBY language. Both methods do the same only difference is in syntax

also listed sample code for each method. Hope this would helpful for you guys.

BROWSER OBJECT SELENIUM METHODS  



Description
Java Method Name
Ruby Method Name
1
Create instance of Fire Fox Driver
WebDriver driver = new FirefoxDriver();
driver= Selenium::Webdriver.for Firefox
2
Create instance of Chrome Driver
WebDriver driver = new ChromeDriver();
driver= Selenium::Webdriver.for Chrome
3
Create instance of IE Driver
WebDriver driver = new IEDriver();
driver= Selenium::Webdriver.for IE
4
Create instance of Safari Driver
WebDriver driver = new SafariDriver();
driver= Selenium::Webdriver.for Safari
5
Navigate to the page specified in the URL.
It does exactly the same thing as the get() method.
navigate().to(url)
code ex:
driver.navigate().
to("http://www.google.com")
get(url
code ex: driver.get("http://www.google.com"))
6
Navigate to the page specified in the URL.
It does exactly the same thing as the get() method.
Only diff between navigate() and get() method is get() method will untill the page loads.
navigate().refresh()

code ex: driver.navigate().refresh()
navigate().refresh()

code ex:
driver.navigate().refresh()
7

It refreshes the current page.
navigate().refresh()
code ex: driver.navigate().refresh()
navigate().refresh()
code ex:
driver.navigate().refresh()
8

It clicks the Browser back button.

navigate().back()
code ex: driver.navigate().back()

navigate().back()
code ex: driver.navigate().back()
9

It clicks the Browser forward button.
navigate().forward()
code ex: driver.navigate().forward()
navigate().forward()
code ex: driver.navigate().forward ()
10

It closes only the current browser that WebDriver is currently controlling/ opened.
To close current WebDriver Instance, We can use Close() method
close()
code ex: driver.close()
close()
code ex: driver.close()
11

It closes all windows that WebDriver has opened.
Quit() method more effective than close()
quit()
code ex: driver.quit()
quit()
code ex: driver.quit()
12
Swich the focus from the controlling browser to ALERT OR WINDOW OR FRAME.
swithTo()
swith_to
13
Capture the text from alert
alert().getText();
code:
String alrtmsg = driver.switchTo().alert().getText();
alert().text();
code:
alrtmsg = driver. swith_to.alert().text();
14
Perform OK operation
alert().accept();
code: driver.switchTo().alert().accept();
alert().accept();
code:
 driver. swith _to().alert().accept();
15
Perform Cancel operation
alert().dismiss();
code: driver.switchTo().alert().dismiss();
alert().dismiss();
code:
 driver. swith_to ().alert().dismiss();
16

It clicks the Browser forward button.
navigate().forward()
code ex: driver.navigate().forward()
navigate().forward()
code ex: driver.navigate().forward ()
17

It closes only the current browser that WebDriver is currently controlling/ opened.
To close current WebDriver Instance, We can use Close() method
close()
code ex: driver.close()
close()
code ex: driver.close()
18

It closes all windows that WebDriver has opened.
Quit() method more effective than close()
quit()
code ex: driver.quit()
quit()
code ex: driver.quit()
19
Swich the focus from the controlling browser to ALERT OR WINDOW OR FRAME.
swithTo()
swith_to
20
Capture the text from alert
alert().getText();
code:
String alrtmsg = driver.switchTo().alert().getText();
alert().text();
code:
alrtmsg = driver. swith_to.alert().text();
21
Perform OK operation
alert().accept();
code: driver.switchTo().alert().accept();
alert().accept();
code:
 driver.swith _to().alert().accept();
22
Switch the focus to FRAME
switchTo().frame(frame)
argument would be either frame tag, element, index
Switch_to().frame(frame)
23
Switch the focus to Window
switchTo().window(windowhandle)
argument would be windowhandle
switch_to.window(windowhandle)
24
Maximize window
diver.manage().window().maximize();
driver.manage.window.maximize
25
Perform Cancel operation
alert().dismiss();
code: driver.switchTo().alert().dismiss();
alert().dismiss();
code:
 driver. swith_to ().alert().dismiss();

WEB OBJECTS METHOD
 (TEXTFILED, CHECKBOX, RADIO,LINK, BUTTON, IMAGE)



    TEXT BOX

26
To enter values Into text boxes
sendKeys(value)
send_Keys(value)
27
To retrieve value from textbox
getText()
text()


CHECKBOX

28
toggle the element on /off
click()
click()


RADIOBUTTON

29
toggle the element on /off
click()
click()


LINK

30
Click on the link
click()
click()


BUTTON

31
click the element
click()
click()
32
Submit the element
submit()
submit()


                                              DROPDOWN BOX

33
Select the option using the displayed text.
selectByVisibleText()
select_by(:text,textvalue)
34
select by index
selectByIndex()
select_by(:index,indexvalue)
35
select by value
selectByValue()
select_by(:value,"")
36
deselect by text
deselectByVisibleText()
deselect_by(:text,textvalue)
37
deselect by index
deselectByIndex()
deselect_by(:index,indexvalue)
38
deselect by value
deselectByValue()
deselect_by(:value,value)
39
Select All values
selectAll()
select_all
40
Deselect all values
deselectAll()
deselect_all
41
Get all values from the dropdown box and return array

options
42
Get only selected options and return array.

selected_options
43
To check element support multiple selection- like list box.
isMultiple()
multiple?


    COMMON METHODS ELEMENTS

44
Is Element enabled? Returns true/false
isEnabled()
enabled?
45
Is Element selected? Returns true/false
isSelected()
selected?
46
Clear the element values
clear()
clear()
47
Get the attribute name
Ex: attributes are 'value', 'Id ,'name'
attribute(name)
attribute(name)
48
Is Element displayed? Returns true/false.
isDisplayed()
displayed?


  WAIT METHODS

49
Wait
Thread.sleep(4000);
sleep()
50
Implicit wait
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.manage.timeouts.implicit_wait = 10
51
Explicit wait
1. WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='gbqfq']")));

2. WebDriverWait wait = new WebDriverWait(driver, 15); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//div[@id='timeLeft']"), "Time left: 7 seconds")); - See more at: http://software-testing-tutorials-automation.blogspot.com/2014/01/selenium-webdriver-tutorials-basic.html#sthash.o3rOMXgU.dpuf
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
// wait until the element appeared
element = wait.until { driver.find_element(:id => "some-dynamic-element") }

No comments:

Post a Comment