Tuesday, January 12, 2016

Ideas

Work on creating methods (reusable methods)

Datatable: How to open or access excel using selenium -- using Apache POI package


1/12/2016

source: http://www.apache.org/dyn/closer.lua/poi/release/bin/poi-bin-3.13-20150929.zip

Basic java code cannot access Excel directly we need import package poi.apache.org

The Apache POI Project's mission is to create and maintain Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft's OLE 2 Compound Document format (OLE2). In short, you can read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using Java. Apache POI is your Java Excel solution (for Excel 97-2008). We have a complete API for porting other OOXML and OLE2 formats and welcome others to participate.

From stackoverflow:

1. You can use this api to read excel rows from java: http://jexcelapi.sourceforge.net/ The tutorial is great and can be found here: http://www.andykhan.com/jexcelapi/tutorial.html

2. There are many API's in java available to read data from Excel.
  1. JExcelApi.
  2. POI
3. Work Around
Save Excel as CSV files (in case you don't want to use any external API)and read them normally as a text file. But use Comma as Separator.
Check this link for more information: read/write excel file in java
I hope this helps :-)
Apache POI to access Excel http://poi.apache.org/spreadsheet/index.html


looks like jar files are available in:

http://apache.mirrors.hoobly.com/poi/release/bin/poi-bin-3.13-20150929.zip

The table below synopsizes the comparative features of POI's Spreadsheet API:
Spreadsheet API Feature Summary
Spreadsheet API Feature Summary




import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.IOException;

import org.apache.poi.xssf.usermodel.*;

public class connectingtoExcelandextractingdata {

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

XSSFWorkbook srcBook = new XSSFWorkbook("c/prop.xlsx");     
        XSSFSheet sourceSheet = srcBook.getSheetAt(0); 

   
}

}

Third Party tools -- handling desktop applciations(Windows)

 1/12/2015

Selenium is used only for web applications, but your code is interrupted with Desktop authentication pop ups, use third party tools like Auto IT and Sikuli.

Auto IT - has record and playback that way you could make use of the recorded code.

Code in Auto IT is .exe file, you just need to call  the .exe file from Selenium code.

Scenario:
To download pdf file from the web page.



Monday, December 21, 2015

Xpath

Note:
- xpath("") --- location paths should be in double quotes
- xpath("//node[@attribute='xcvv']") --- every attribute declaration should be inside [] and value of attribute should be in single quote.

Regular Expression in Xpath??


  • We can join two conditions using and
          xpath = //<tag name>[@<attribute name>='<value>'  and @value='1']

  • Use Higlight, adjacent to Xpath section in inspect by Firepath window, when you click Highlight it will show the web element that xpath is refering too. That way you can validate the xpath, whether its pointing out to the proper web element. Dont forget to enter xpath in the field.
  • Regular Expression in xpath:
           xpath = //<tag name>[starts-with(@<attribute name>,'<value>')]

           Following could be used:
           ends-with
           contains


12/21/2015

Source: http://www.w3.org/TR/xpath/

Here are some examples of location paths using abbreviated syntax:
  • para selects the para element children of the context node
  • * selects all element children of the context node
  • text() selects all text node children of the context node
  • @name selects the name attribute of the context node
  • @* selects all the attributes of the context node
  • para[1] selects the first para child of the context node
  • para[last()] selects the last para child of the context node
  • */para selects all para grandchildren of the context node
  • /doc/chapter[5]/section[2] selects the second section of the fifth chapter of the doc
  • chapter//para selects the para element descendants of the chapter element children of the context node
  • //para selects all the para descendants of the document root and thus selects all para elements in the same document as the context node
  • //olist/item selects all the item elements in the same document as the context node that have an olist parent
  • . selects the context node
  • .//para selects the para element descendants of the context node
  • .. selects the parent of the context node
  • ../@lang selects the lang attribute of the parent of the context node
  • para[@type="warning"] selects all para children of the context node that have a type attribute with value warning
  • para[@type="warning"][5] selects the fifth para child of the context node that has a type attribute with value warning
  • para[5][@type="warning"] selects the fifth para child of the context node if that child has a type attribute with value warning
  • chapter[title="Introduction"] selects the chapter children of the context node that have one or more title children with string-value equal to Introduction
  • chapter[title] selects the chapter children of the context node that have one or more title children
  • employee[@secretary and @assistant] selects all the employee children of the context node that have both a secretary attribute and an assistant attribute
The most important abbreviation is that child:: can be omitted from a location step. In effect, child is the default axis. For example, a location path div/para is short for child::div/child::para.
There is also an abbreviation for attributes: attribute:: can be abbreviated to @. For example, a location path para[@type="warning"] is short for child::para[attribute::type="warning"] and so selects para children with a type attribute with value equal towarning.
// is short for /descendant-or-self::node()/. For example, //para is short for /descendant-or-self::node()/child::para and so will select any para element in the document (even a para element that is a document element will be selected by //para since the document element node is a child of the root node); div//para is short for div/descendant-or-self::node()/child::para and so will select all para descendants of div children.
NOTE: The location path //para[1] does not mean the same as the location path /descendant::para[1]. The latter selects the first descendant para element; the former selects all descendant para elements that are the first para children of their parents.
A location step of . is short for self::node(). This is particularly useful in conjunction with //. For example, the location path .//para is short for
self::node()/descendant-or-self::node()/child::para
and so will select all para descendant elements of the context node.
Similarly, a location step of .. is short for parent::node(). For example, ../title is short for parent::node()/child::title and so will select the title children of the parent of the context node.


More examples are covered in the following website

http://hedleyproctor.com/2011/05/tutorial-writing-xpath-selectors-for-selenium-tests/
There are a number of ways to write and test an XPath expression:
  1. Using the Selenium IDE itself – it has a “test” option.
  2. Using Firebug and a separate XPath tester.
  3. Using Firebug and the FirePath tester, which is a separate add-on but integrates with Firebug.

Other websites:

http://zvon.org/comp/r/ref-XPath_1.html


3/2/2016:

Ways of Validating Xpath:

xpath could be validated or written on own to find web objects in web pages. And process of writing and finding xpath is possible in many ways, for an example in

My Experience:

Chrome 
- One could write the xpath by following below process

F12->ctrl+F-> Enter xpath in the field opened.

- To generate xpath, you could go to element, right click on it -> Inspect -> Go to the inspect code and Right click -> Copy the xpath.

You could use this process, when ever you are working on finding element in a web page.

FireFox:

Firebug and Firepath  are the two addins that would help you to validate your xpath.

Source:
http://stackoverflow.com/questions/22571267/how-to-verify-an-xpath-expression-in-chrome-developers-tool-or-firefoxs-firebug


1. Chrome

This can be achieved by three different approaches (see my blog article here for more details):
  • Search in Elements panel
  • Execute $x() and $$() in Console panel, as shown in Lawrence's answer
  • Third party extensions (not necessary)
Here is how you search XPath in Elements panel:
  1. Press F12 to open Chrome Developer Tool
  2. In "Elements" panel, press Ctrl+F
  3. In the search box, type in XPath or CSS Selector, if elements are found, they will be highlighted in yellow.
enter image description here

2. Firefox

  1. Install Firebug
  2. Install Firepath
  3. Press F12 to open Firebug
  4. Switch to FirePath panel
  5. In dropdown, select XPathor CSS
  6. Type in to locate
enter image description here

3. Chrome and Firefox

You can open a Console in Chrome, and check the XPath by typing $x("your_xpath_here"). This will return an array of matched values. If it is empty, you know there is no match on the page.

enter image description here

Monday, September 21, 2015

Unknown questions in Selenium


Source: http://www.brainmeasures.com/e_notes_and_certification.aspx

- Finding an element ending with specific letter, how do you write the xpath or regular exp in selenium??

Try: Use of Contains method: 
xpath("//<nearest tag name>@contains(<attribute>,"text"))



- What is Selenium 2

- Selenium has an ____________ that allows us to fire the event that is attached to elements on a page.

- The Default Selenium object takes _________parameters in its constructor.

- The command runs the snippet within the Selenium object.
http://www.seleniumwiki.com/selenium-rc/example-of-store-storeeval-and-geteval-in-selenium/

- To initialize the Selenium object how many parameters it will take

- What is the annotation we put above our setUp() to make sure we pass in the browser?


- If you wanted to validate that a button, which has appeared, is on a page, what two commands would be the best to use?

a) Verify Text Present/assert Text Present
b) Verify Element Present/assert Element Present
c) Verify Alert Present/assert Alert Present
d) Verify Alert/assert Alert

- What is the node inside the node that allows us to specify the browser?

a) Limit
b) Bound
c) Constraint
d) Parameter

- ________Finds the item ending with the value passed in. This is the equivalent to the X Path ends-with.

a) &=
b) *=
c) ^=
d) $=

-
Are you still required to use Browserbot in your JavaScript?

- Selenium cannot always type into --------------------------------- areas.
a) Content Editable
b) Content Erasable
c) Content Writable
d) None of the above

- When we wanted to find if there was text with Cap on the page, we put a _______ at the start and end of the pattern.

a) #
b) /
c) *
d) &


- Selenium and are being merged to create the new Selenium 2 code framework.

a) remoteWebDriver
b) webtesting
c) webDrives
d) webDriver


- What is the desktop viewing application Castro relies on?

a) VCG
b) VRC
c) VNC
d) VNG

- _______________ are used extensively throughout Selenium as the default pattern matching technique.

a) Globbing
b) Expressions
c) Globs
d) Characters

- What is the name of the library we used to record video?

a) Citrine
b) Castro
c) Castrate
d) None of the above


- To find an element by ID in a CSS selector, we need to place a _____________ in front of the ID of the element in the CSS selector.

a) !
b) #
c) $
d) *


- __________________is a way to wrap up the Window object within Selenium that Firefox adds and only allows access to very basic DOM calls.

a) XPC Native Wrapped
b) XPC Native Wrapper
c) XPM Nate Wrap
d) XPN Nate Wrap


- What class do we need to extend when writing JUnit 3 style tests?

a) Selenium Test Case
b) Selenese Test Case
c) Seleneum Test Care
d) Selenium IDE tests


- Which command is used to get the string?

a) StoreVariable command
b) StoreData command
c) StoreText command
d) StoreRecord command


- Selenium and are being merged to create the new Selenium 2 code framework.

a) remoteWebDriver
b) webtesting
c) webDrives
d) webDriver


- How do you start the browser?

a) Call the execute() function
b) Call the run() function
c) Call the proceed() function
d) Call the start() function


- The_________ node in the TestNG configuration file also stores which test classes these parameters are going to be used in.

a) <test>
b) <check>
c) <analysis>
d) <trial>


- From which method we can stop the browser?

a) exit () method
b) stop() method
c) pause() method
d) end() method


- How would you get all the cookies that are on the page?

a) acquireCookie()
b) obtainCookie()
c) getCookie()
d) catchCookie()


- The one window will hold the_____________ with the Test Suite on the left-hand side.

a) Selenium Code Framework
b) Selenium Core Framework
c) Selenium Framework
d) Selenium Core


- ____________ file that contains all the configurations that Selenium grid has.

a) YACL
b) YANL
c) YAML
d) YAPL


- How many Mechanisms are for validating elements that are available on the application under test?

a) 3
b) 4
c) 2
d) 5


-
If we want to access the DOM in your test without using a specific Selenium command, you will need to access it through this special object. This object is called __________?

a) DOM access
b) browser access
c) browserboat
d) browserbot


- How do you store variables to be used later in the test?

a) Use the storedVars dictionary
b) Create a new variable that has global scope
c) You cannot store variables using user extensions
d) You can store variables using user extensions

- How do you specify the port the Remote Control is running on?

a) Dport=portSeries
b) Dport=portNumber
c) Dport=port
d) Dport=portCount

- What is the command required to start the Hub?

a) ant launch-network
b) ant launch –hub
c) ant launch-caption
d) None of the above

Handling Cookies

Selenium 1 vs Selenium 2