Work on creating methods (reusable methods)
Tuesday, January 12, 2016
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.
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 :-)
- JExcelApi.
- POI
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
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);
}
}
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
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.
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??
Following could be used:
ends-with
contains
12/21/2015
Source: http://www.w3.org/TR/xpath/
http://hedleyproctor.com/2011/05/tutorial-writing-xpath-selectors-for-selenium-tests/
Other websites:
http://zvon.org/comp/r/ref-XPath_1.html
3/2/2016:
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
- 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
- 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:
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:
paraselects theparaelement children of the context node*selects all element children of the context nodetext()selects all text node children of the context node@nameselects thenameattribute of the context node@*selects all the attributes of the context nodepara[1]selects the firstparachild of the context nodepara[last()]selects the lastparachild of the context node*/paraselects allparagrandchildren of the context node/doc/chapter[5]/section[2]selects the secondsectionof the fifthchapterof thedocchapter//paraselects theparaelement descendants of thechapterelement children of the context node//paraselects all theparadescendants of the document root and thus selects allparaelements in the same document as the context node//olist/itemselects all theitemelements in the same document as the context node that have anolistparent.selects the context node.//paraselects theparaelement descendants of the context node..selects the parent of the context node../@langselects thelangattribute of the parent of the context nodepara[@type="warning"]selects allparachildren of the context node that have atypeattribute with valuewarningpara[@type="warning"][5]selects the fifthparachild of the context node that has atypeattribute with valuewarningpara[5][@type="warning"]selects the fifthparachild of the context node if that child has atypeattribute with valuewarningchapter[title="Introduction"]selects thechapterchildren of the context node that have one or moretitlechildren with string-value equal toIntroductionchapter[title]selects thechapterchildren of the context node that have one or moretitlechildrenemployee[@secretary and @assistant]selects all theemployeechildren of the context node that have both asecretaryattribute and anassistantattribute
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 descendantparaelement; the former selects all descendantparaelements that are the firstparachildren 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 forself::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:
- Using the Selenium IDE itself – it has a “test” option.
- Using Firebug and a separate XPath tester.
- 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
Elementspanel - Execute
$x()and$$()inConsolepanel, as shown in Lawrence's answer - Third party extensions (not necessary)
Here is how you search XPath in
Elements panel:- Press F12 to open Chrome Developer Tool
- In "Elements" panel, press Ctrl+F
- In the search box, type in XPath or CSS Selector, if elements are found, they will be highlighted in yellow.
2. Firefox
- Install Firebug
- Install Firepath
- Press F12 to open Firebug
- Switch to
FirePathpanel - In dropdown, select XPathor CSS
- Type in to locate
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.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
source:
http://shantonusarker.blogspot.com/2012/12/handling-cookie-in-selenium-webdriver.html
Creating and Deleting cookies?
http://shantonusarker.blogspot.com/2012/12/handling-cookie-in-selenium-webdriver.html
Creating and Deleting cookies?
Subscribe to:
Posts (Atom)