Showing posts with label Selenium Basics. Show all posts
Showing posts with label Selenium Basics. Show all posts

October 30, 2015

Run selenium tests in Chrome and IE browser

October 30, 2015 27
How to run the selenium test scripts in Chrome/IE browser ?

To run the selenium test cases in Chrome/IE browser is necessary and need of today's web world as Chrome being the one of the best and most widely used web browser.

Selenium by default supports only Mozilla Firefox . 

To run your tests in Chrome browser please do the following set-up.

1. Download chrome browser related jar file from here.

2. Set the System configuration by adding the following code.

System.setProperty("webdriver.chrome.driver", "Path to chrome related jar file downloaded in step 1");
WebDriver driver = new ChromeDriver();

To run the test in Internet explorer.

1. Download IE browser related jar file from here.

2. Set the System configuration by adding the following code.

System.setProperty("webdriver.ie.driver", "C:\\Users\\ajain5\\Downloads\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();



October 2, 2015

Handling webtables

October 02, 2015 58
Handling webtables
This post explains about Handling Webtables.

Get Number of Columns
Get Number of Rows
Get Content of a specific cell based on Row and Column value.

Below is the code:



August 3, 2015

Check all check boxes and verify status of check box

August 03, 2015 1
One more example from dave haeffner's weekly tip...

The Problem

Checkboxes, an often used element in web applications. But how do you work with them in your Selenium tests? Intuitively you may reach for a method that has the word 'checked' in it -- like .checked? or .isChecked. But this doesn't exist in Selenium. So how do you do it?

A Solution

There are two ways to approach this -- through an element's 'checked' attribute (a.k.a. an attribute lookup), or by asking the element if it is selected.
boolean org.openqa.selenium.WebElement.isSelected()

  • isSelected

    boolean isSelected()
    Determine whether or not this element is selected or not. This operation only applies to input elements such as checkboxes, options in a select and radio buttons.
    Returns:
    True if the element is currently selected or checked, false otherwise.
Below example shows you how to check all check boxes and verify the status of check boxes.




package sample;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class Checkboxes_Test {
 public WebDriver driver;

 @Test
 public void testCheckboxes_Test() throws Exception {

  driver.get("http://the-internet.herokuapp.com");
  driver.findElement(By.linkText("Checkboxes")).click();
  //get all the check boxes in web page
  List<WebElement> cBox=driver.findElements(By.cssSelector("input[type='checkbox']"));
  for (int i = 0; i < cBox.size(); i++) {
   //verify check box status, if it is not checked then perform click operation
   if (!cBox.get(i).isSelected()) {
    cBox.get(i).click();
    System.out.println("Check box "+ i + " status is :"+cBox.get(i).isSelected());
   }
   else
   {
    System.out.println("Check box "+ i + " is already selected and status is :"+cBox.get(i).isSelected());
   }
  }
 }

 @BeforeClass
 public void beforeClass() {
  driver = new FirefoxDriver();
  driver.manage().window().maximize();
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
 }

 @AfterClass
 public void afterClass() throws Exception {
  driver.quit();
 }

}

December 22, 2010

How to declare IE,FF and Chrome in Selenium

December 22, 2010 0
How to declare IE,FF and Chrome in Selenium
Selenium supported browsers include:



  *firefox
  *mock
  *firefoxproxy
  *pifirefox
  *chrome
  *iexploreproxy
  *iexplore
  *firefox3
  *safariproxy
  *googlechrome
  *konqueror
  *firefox2
  *safari
  *piiexplore
  *firefoxchrome
  *opera
  *iehta
  *custom
 on session null


December 13, 2010

Selenium IDE PPT

December 13, 2010 1
Selenium IDE PPT
Here is the good PPT about selenium

Please click the below link...



Presentation Transcript

Selenium Tutorial :

Selenium Tutorial


What is Selenium? :

What is Selenium? • Javascript framework that runs in your webbrowser • Works anywhere Javascript is supported • Hooks for many other languages • Java, Ruby, Python • Can simulate a user navigating through pages and then assert for specific marks on the pages • All you need to really know is HTML to start using it right away


Where to get it? :

Where to get it? • You can use Selenium-Core and customize everything • But it is easier to just get a Firefox plug-in “Selenium-IDE” that helps you “record” test cases • You can record how an app is being used and then play back those recordings followed by asserts • Get everything at: www.openqa.org/selenium/


Selenium IDE :

Selenium IDE The list of actions in the actual test case to execute The root of web application you want to test The log of the events that were executed, including any errors or warning that may have occurred


Selenium IDE :

Selenium IDE Execution Commands Record test actions Try the test in the Web based TestRunner Specify commands, including asserts Reference of the currently selected command 


Test Creation Demo :

Test Creation Demo • Create test case to log into the gallery • Create test case to log out of the gallery


Slide 7:

Start Pixory Connect to the Server Go to the Login Screen Hit the Record Button


Slide 8:

Type in Username and Password Hit record again to stop Hit submit IDE should update


Slide 9:

Add assertTextPresent and type the text to search for Hit play to make sure your test is successful


Creating a Test Suite :

Creating a Test Suite A Test Suite in Selenium is just an HTML file that contains a table of links to tests Demo Test Suite
Demo Test Suite
TestLogin
TestLogout


Executing the Test Suite :

Executing the Test Suite • Selenium Core is a collection of Javascript and HTML with iFrames • Due to security concerns Core must be deployed within the same server as the application being hosted • The simplest way to run Pixory is to just run the Java application and let it use its own server • Problems using Core with Pixory • Selenium IDE is a plug-in for Firefox and thus can go around these restrictions


Running the Test Suite :

Running the Test Suite • We basically want to execute the test suite using the Selenium IDE plug-in TestRunner.html chrome://selenium-ide/content/selenium/TestRunner.html? baseURL=&test=file:///&auto=true chrome://selenium-ide/content/selenium/TestRunner.html? baseURL=http://localhost:8081&test=file:///Users/ms333/ projects/classes/running/v_and_v/hw3/selenium/test/ TestSuite.html&auto=true


Test Suite :

Test Suite


Test Suite :

Test Suite Execution Control Test Cases Steps of the test case Application being tested


Test Runner Control :

Test Runner Control


Test Runner Control :

Test Runner Control Pause/Play Execution Step through Execution Control Speed of Execution Summary of the Test View the log of the current execution View the DOM of the current Page being tested Highlight Elements in the Execution Run All Tests Run Selected Test


TestRunner Demo :

TestRunner Demo Execute Tests created inside the Firefox TestRunner.  

December 5, 2010

Selenium Commands

December 05, 2010 3
Selenium Commands

Element Locator

Element Locators tell Selenium which HTML element a command refers to.
The format of a locator is:  locatorType=argument
Example: - (“link=click”)
Selenium supports the following strategies for locating elements:
id=id
Select the element with the specified @id attribute
name=name
Select the first element with the specified @name attribute.
·         username
·         name=username
xpath=xpathExpression
Locate an element using an XPath expression.
·         xpath=//img[@alt='The image alt text']
·         xpath=//table[@id='table1']//tr[4]/td[2]
link=textPattern
Select the link (anchor) element which contains text matching the specified pattern.
·         link=The link text


  Important Selenium Commands


Command
Usage
Description
start()
selenium.start();
Launches the browser with a new Selenium session
stop()
selenium.stop();
Ends the current Selenium testing session (normally killing the browser)
 click()
selenium.click("link=Home");
selenium.click("name=send");
Clicks on a link, button, checkbox or radio button. If the click action causes a new page to load (like a link usually does), call waitForPageToLoad.
doubleClick()

Double clicks on a link, button, checkbox or radio button. If the double click action causes a new page to load (like a link usually does), call waitForPageToLoad.
type()
Type(
   
string locator,
   
string value
);

selenium.type("name=login[username]", ndasam);
Sets the value of an input field, as though you typed it in. Can also be used to set the value of combo boxes, check boxes, etc. In these cases, value should be the value of the option selected, not the visible text.

check()
Check(
   
string locator
);
selenium.check ("guest”);
Check a toggle-button (checkbox/radio)
 uncheck()
Uncheck(
   
string locator
);
Uncheck a toggle-button (checkbox/radio)
 select()
Select(
   
string selectLocator,
   
string optionLocator
);
selenium.select("payware_expiration_yr", "label=2010”);

Select an option from a drop-down using an option locator.





November 19, 2010

Selenium Basics Part - 3

November 19, 2010 1
Selenium Basics Part - 3

Selenium Commands – Selenese


A command is what tells Selenium what to do. Selenium commands come in three “flavors”:Actions, Accessors and Assertions.
  • Actions are commands that generally manipulate the state of the application. They do things like “click this link” and “select that option”. If an Action fails, or has an error, the execution of the current test is stopped.
Many Actions can be called with the “AndWait” suffix, e.g. “clickAndWait”. This suffix tells Selenium that the action will cause the browser to make a call to the server, and that Selenium should wait for a new page to load.
  • Accessors examine the state of the application and store the results in variables, e.g. “storeTitle”. They are also used to automatically generate Assertions.
  • Assertions are like Accessors, but they verify that the state of the application conforms to what is expected. Examples include “make sure the page title is X” and “verify that this checkbox is checked”.

Script Syntax

Selenium commands are simple, they consist of the command and two parameters. For example:
verifyText
//div//a[2]
Login
The parameters are not always required; it depends on the command. In some cases both are required, in others one parameter is required, and in still others the command may take no parameters at all. Here are a couple more examples:
goBackAndWait


verifyTextPresent

Welcome to My Home Page
type
id=phone
(555) 666-7066
type
id=address1
${myVariableAddress}
The command reference describes the parameter requirements for each command.
Parameters vary, however they are typically:
  • a locator for identifying a UI element within a page.
  • a text pattern for verifying or asserting expected page content
a text pattern or a selenium variable for entering text in an input field or for selecting an option from an option list.







Test Suites
A test suite is a collection of tests. Often one will run all the tests in a test suite as one continuous batch-job.
When using Selenium-IDE, test suites also can be defined using a simple HTML file. The syntax again is simple. An HTML table defines a list of tests where each row defines the filesystem path to each test. An example tells it all.
Test Suite Function Tests - Priority 1


A file similar to this would allow running the tests all at once, one after another, from the Selenium-IDE.
Test suites can also be maintained when using Selenium-RC. This is done via programming and can be done a number of ways. Commonly Junit is used to maintain a test suite if one is using Selenium-RC with Java. Additionally, if C# is the chosen language, Nunit could be employed. If using an interpreted language like Python with Selenium-RC than some simple programming would be involved in setting up a test suite. Since the whole reason for using Sel-RC is to make use of programming logic for your testing this usually isn’t a problem.


Commonly Used Selenium Commands
To conclude our introduction of Selenium, we’ll show you a few typical Selenium commands. These are probably the most commonly used commands for building tests.
open
opens a page using a URL.
click/clickAndWait
performs a click operation, and optionally waits for a new page to load.
verifyTitle/assertTitle
verifies an expected page title.
verifyTextPresent
verifies expected text is somewhere on the page.
verifyElementPresent
verifies an expected UI element, as defined by its HTML tag, is present on the page.
verifyText
verifies expected text and it’s corresponding HTML tag are present on the page.
verifyTable
verifies a table’s expected contents.
waitForPageToLoad
pauses execution until an expected new page loads. Called automatically when clickAndWait is used.
waitForElementPresent
pauses execution until an expected UI element, as defined by its HTML tag, is present on the page.
Summary
Now that you’ve seen an introduction to Selenium, you’re ready to start writing your first scripts. We recommend beginning with the Selenium IDE and its context-sensitive, right-click, menu. This will allow you to get familiar with the most common Selenium commands quickly, and you can have a simple script done in just a minute or two. 

Locating Elements

For many Selenium commands, a target is required. This target identifies an element in the content of the web application, and consists of the location strategy followed by the location in the format locatorType=location. The locator type can be omitted in many cases. The various locator types are explained below with examples for each

Locating by Id

Locating by Name

Locating by XPath

Locating Hyperlinks by Link Text

Locating by DOM

Locating by CSS


Store commands

storeElementPresent

This corresponds to verifyElementPresent. It simply stores a boolean value–”true” or “false”–depending on whether the UI element is found.

storeText

StoreText corresponds to verifyText. It uses a locater to identify specific page text. The text, if found, is stored in the variable. StoreText can be used to extract text from the page being tested.

storeEval

This command takes a script as its first parameter. Embedding JavaScript within Selenese is covered in the next section. StoreEval allows the test to store the result of running the script in a variable.






Selenium Basics Part - 2

November 19, 2010 3
Selenium Basics Part - 2

Get started with Selenium!


1.    Watch: see the magic.


This video will tell you how to record tests using Selenium IDE.

2.    Begin: write and run tests in Firefox

Selenium IDE is a Firefox add-on that records clicks, typing, and other actions to make a test, which you can play back in the browser.

3.    Customize: your language, your browser.

Selenium Remote Control (RC) runs your tests in multiple browsersand platforms. Tweak your tests in your preferred language.

4.    Deploy: scale out, speed up.

Selenium Grid extends Selenium RC to distribute your tests across multiple servers, saving you time by running tests in parallel.

Who should use it? 

Developers can use it - for “browser” regression testing ( and replace htmlunit/httpunit in some cases) .
Per the one of the forces behind selenium(Neal ford) - it should really be used by Business Analyst first .
QA should enhance/use it do regression test/cross browsers testing on all platforms .

Platforms Supported by Selenium

Browsers

Browser
Selenium IDE
Selenium Remote Control
Selenium Core
Firefox 3
Record and playback tests
Start browser, run tests
Run tests
Firefox 2
Record and playback tests
Start browser, run tests
Run tests
IE 8
not supported
Start browser, run tests
Run tests
IE 7
not supported
Start browser, run tests
Run tests
Safari 3
not supported
Start browser, run tests
Run tests
Safari 2
not supported
Start browser, run tests
Run tests
Opera 9
not supported
Start browser, run tests
Run tests
Opera 8
not supported
Start browser, run tests
Run tests
Others
not supported
Partial support possible*
Run tests**

Operating Systems

OS
Selenium IDE
Selenium Remote Control
Selenium Core
Windows
Works in Firefox 2+
Start browser, run tests
Run tests
OS X
Works in Firefox 2+
Start browser, run tests
Run tests
Linux
Works in Firefox 2+
Start browser, run tests
Run tests
Solaris
Works in Firefox 2+
Start browser, run tests
Run tests
Others
Should work in Firefox 2+
Start browser, run tests*
Run tests**

Programming Languages

Programming languages are supported through Selenium Remote Control "drivers." These are libraries made for each language that expose commands from the Selenium API natively in the form of methods/functions.
Language
Selenium IDE
Selenium Remote Control
Selenium Core
C#
Generate code
Library ("driver") support
n/a
Java
Generate code
Library ("driver") support
n/a
Perl
Generate code
Library ("driver") support
n/a
PHP
Generate code
Library ("driver") support
n/a
Python
Generate code
Library ("driver") support
n/a
Ruby
Generate code
Library ("driver") support
n/a
Others
Generate custom code*
Commands via HTTP requests**
n/a

Testing Frameworks

Testing frameworks aren't required, but they can be helpful if you want to automate your tests.
Framework
Selenium IDE
Selenium Remote Control
Selenium Core
Bromine
Comes with template to add to IDE
Manipulate browser, check assertions via custom driver
Special support**
JUnit
Out-of-the-box code generation
Manipulate browser, check assertions via Java driver
n/a
NUnit
Out-of-the-box code generation
Manipulate browser, check assertions via .NET driver
n/a
RSpec (Ruby)
Custom code generation template*
Manipulate browser, check assertions via Ruby driver
n/a
Test::Unit (Ruby)
Out-of-the-box code generation
Manipulate browser, check assertions via Ruby driver
n/a
TestNG (Java)
Custom code generation template*
Manipulate browser, check assertions via Java driver
n/a
unittest (Python)
Out-of-the-box code generation
Manipulate browser, check assertions via Python driver
n/a
Others
Custom code generation template*
Manipulate browser, check assertions via HTTP requests***
n/a
n/a
Utilizes the Python driver
n/a