Showing posts with label Locators In Selenium. Show all posts
Showing posts with label Locators In Selenium. Show all posts

Tuesday, 5 August 2014

Locators In Selenium

Locators
Selenium uses what is called locators to find and match the elements of your page that it needs to interact with. There are 8 locators strategies included in Selenium:
  • Identifier
  • Id
  • Name
  • Link
  • DOM
  • XPath
  • CSS
  • UI-element
 Identifier
Works with the ID and name attributes of your html tags. Let’s consider the following example:
<html>
<body>
<form id=”login”>
<input name=”username” type=”text”/>
<input name=”password” type=”password”/>
<input name=”submit” type=”submit” value=”Continue!”/>
</form>
</body>
</html>
Valid locators for this snippet are :
  • identifier=login
  • identifier=username
  • submit
Id
The Id strategy looks for an element in the page having an id attribute corresponding to the specified pattern. <label id=”my_id” /> will be matched by a locator like id=my_id or just my_id
 Name
Like the Id strategy, but on the name attribute. You can also specify a filter to refine your locator. Currently, there are two filter types :
  • Value : matches elements with a name attribute and where the value follows a pattern. The following example illustrates the interest of filters :
  • <html>
  •  <body>
  •    <div id=”pancakes”>
  •      <button type=”button” name=”pancake” value=”Blueberry”>Blueberry</button>
  •      <button type=”button” name=”pancake” value=”Banana”>Banana</button>
  •      <button type=”button” name=”pancake” value=”Strawberry”>Strawberry</button>
  •    </div>
  •  </body>
</html>
Link
This strategy is intended to select links only and selects the anchor element containing the specified text: link=The text of the link
DOM
The DOM strategy works by locating elements that matches the javascript expression refering to an element in the DOM of the page.
  • dom=document.div['pancakes'].button[0]
  • document.div[0].button[2]
  • dom=function foo() { return document.getElementById(“pancakes”); }; foo();
XPath
While DOM is the recognized standard for navigation through an HTML element tree, XPath is the standard navigation tool for XML; and an HTML document is also an XML document (xHTML). XPath is used everywhere where there is XML. Valid XPath locators can be:
  • xpath=//button[@value="Blueberry"]: matches the Blueberry button
  • //div[@id="pancakes"]/button[0]: same thing
CSS
The CSS locator strategy uses CSS selectors to find the elements in the page. Selenium supports CSS 1 through 3 selectors syntax excepted CSS3 namespaces

Thursday, 10 July 2014

Selenium Online Training by Quontra Solutions

We are pleased to supply a lot of information and a dozen of free hands-on tutorials. All the available tutorials are surrounded with screenshots and downloadable code samples. This blog is created and will be maintained by Quontra Solutions. Quontra solutions Trainers have many years of experience in automated testing. Quontra Solutions is particularly interested in web technology and new programming languages. We are always trying to find a way to transfer knowledge to Students who are interested in the automated testing of software.
A variety of topics will be covered on this blog. Starting with recording tests with Selenium IDE and locating web elements and furthermore the use of design patterns and performance measurement to create a robust testing framework.
Selenium Tutorial using C# and NUnit
In this tutorial we are going to learn how to create your first test script using the language that most commonly used, c#. Since most languages are semantically the same, if you do not use c# it shouldn’t be too difficult to translate the tutorial into your language of choice. You have to download Nunit and at least Visual Studio Express c# edition to complete this tutorial. They are free to download and use.
  1. Follow steps 1-4 of Selenium Remote Control HTML Suite Tutorial. This will get the Selenium Remote Control Running.
  2. In Visual Studio let’s create a new project. You will have to create a new class library by going New> New Solution> Class Library and call it TheAutomatedTester
  3. Add a reference to the NUnit Framework by rightclicking on the solution and clicking add reference. Click on the browse tab and navigate to <%nunithome%>\bin and select nunit.framework.dll . This allows you now to create your first NUnit test.
  4. Now in the *.cs file put the code below into it. The code below will call Selenium Remote and say that it needs an instance on Firefox Chrome.
  1.        [TestFixture]
  2.        public class TheAutomatedTester
  3.        {
  4.                private ISelenium selenium;
  5.            private StringBuilder verificationErrors;
  6. [SetUp]
  7. public void SetupTest()
  8. {
  9.        selenium = new DefaultSelenium(“localhost”, 4444, “*chrome”, “http://localhost”);
  10. selenium.Start();
  11. verificationErrors = new StringBuilder();
  12.    }


  1. Now Lets create a test:
  1. [Test]
  2. public void AutomatedTester_Test()
  3. {
  4. selenium.Open(“/index.htm”);
  5. selenium.Click(“buttonName”);
  6. selenium.WaitForPageToLoad(“30000″);
  7. }
The code above would open the page index.htm for the root of your local web server then click on a button and wait for a page to load. If you want to see how to the other commands look I would suggest creating your command in Selenium IDE and then converting them to c# using the Options > Format commands.
  1. Once your test has run you will need to clean up Selenium object. The best way to do this is to create a teardown function in your test. It should look like something like the code below.
  1. [TearDown]
  2. public void TeardownTest()
  3. {
  4. try
  5. {
  6. selenium.Stop();
  7. }
  8. catch (Exception)
  9. {// Ignore errors if unable to close the browser
  10. }
  11. Assert.AreEqual(“”, verificationErrors.ToString());
  12. }
If you make sure that your code has this teardown then you will be able to reuse the Selenium Remote Control.
  1. Now compile the code into a DLL and Open it with NUnit. When you click the Run button in NUnit it will run your Selenium Test.
If you would like to make your test data driven put all the code to pull the data in the SetUp

Friday, 4 July 2014

Usage of sql jdbc 4.0 driver

This post is related to using sql jdbc driver 4.0

If you are using sql jdbc driver then these are things to note and follow:
1) Download sqljdbc driver from http://www.microsoft.com/en-in/download/details.aspx?id=11774
2) Now if your jdk is 32-bit then set the 32-bit driver path to your system property or 64-bit if your jdk is 64-bit
3) Now if you are using integrated security then copy the authorization .dll to your system32 folder and set that property to your system path as well.
4) If you still get issues with it then let us know