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

Monday, January 19, 2015

How to use Array in Selenium IDE

Arrays is a data structure that is using in many programming languages to implementing and manipulating sets of similar type data. In Selenium IDE, Array can be used to enter a sets of data one by one in an input field or clicking on different link or button to repeat the same task.

Here we will explain how it can be performed.

Step 1 : We have a sample task on Selenium page. We want to visit different tabs on selenium page, Tabs are : Project, Download, documentation, Support, About.

I want to make a data structure where I store the tab name in the array and IDE script will read the tab name from Array and execute the click command according to it. Note that we will also implement while loop here.

Array will be,

tab[0]=”Projects”

tab[1]=”Download”

tab[2]=”Documentation”

tab[3]=”Support”

tab[4]=”About”

Step 2 : In order to traversing the Array we need a loop command. In that case we will use while loop but “while” command is not a built in command in selenium IDE. We have to download the user extensions from the following location.

https://docs.google.com/file/d/0B6vnknygMB3ISHBYODA3UDUtS0U/edit?usp=sharing

image

After downloading the user-extension.js file we need to attach it to Selenium IDE.

For this,

  • Go to Options>Options…

image

  • Options window will be displayed and go to General tab.
  • Locate the user-extension.js file and click on OK button.

image

Step 3 : Write the following Selenium command and that will be,

image

Here we use the storeEval and getEval command.

storeEval : Execute the Java script command and return the value and assign the value Value column.

getEval  : Execute the Java script command but does not do any return.

Line 1: Open the application with the base URL : http://www.seleniumhq.org/

Line 2 : Define the array

Command Target Value
storeEval new Array("Projects", "Download", "Documentation","Support","About") tabNameArray

Line 3 : Define a variable.

Command Target Value
getEval tabItems=0;  

Line 4 : Write while command and condition.

Command Target Value
while tabItems<storedVars['tabNameArray'].length  

Note that we use storedVars['tabNameArray'] here to return the array reference.

Line 5 : Store tabItems to TabN

Command Target Value
storeEval tabItems tabN

Line 6 : Return the tab name from tabNameArray and store it to tabName.

Command Target Value
storeEval storedVars['tabNameArray'][storedVars['tabN']] tabName

So, tabNameArray[0] =”Projects”

       tabNameArray[1] =”Download”

       and so on….

Line 7 : Print the tab name.

Command Target Value
echo javascript{storedVars['tabName']}  

Line 8 : Click on the tab by Link name.

Command Target Value
clickAndWait link=${tabName}  

Line 9 : Increase the value for tabItems to 1.

Command Target Value
getEval tabItems++  

Line 10 : End of the while loop.

Command Target Value
endWhile    

Step 4 : Run the script.

In this way we can also store user data to an array and use those array data as input of the application. So driven testing can also be performed in this way. Thanks…

Happy Selenium IDE scripting with Array…

Wednesday, September 17, 2014

How to run Selenium IDE script in different browser

We can easily create selenium script through Selenium IDE and run those scripts on Firefox browser.If you have no idea about selenium script, please visit my other post on IDE (How to record and run scripts with Selenium IDE).
But in order to do cross browser testing we need to run the script on other browsers like chrome, Internet Explorer etc.
Selenium IDE has given a feature (that is still experimental stage) where we can run our recorded IDE scripts through Chrome, Internet Explorer etc.
Step 1 : Download Selenium Standalone server and Browser driver server
Download the selenium Standalone server from the location (http://www.seleniumhq.org/download/).
image
Download the Browser Driver from the following location.
  • Internet Explorer(IE) driver :
    • Go to the location (http://www.seleniumhq.org/download/).
    • Note that there are two different version for 32 bit and 64 bit windows. Click on the appropriate link (32 bit windows IE or 64 bit windows IE) according to your windows OS version (32 or 64 bit).
image
image
image
  • Click to download the latest chrome driver. Here I have downloaded version 2.10. But it might be more latest version in future release. Clicking on this link will go to the following page.
image
  • Click on the above selected link and download the zip file. Unzip the file and copy the EXE file to a single location where Selenium Standalone server and IE driver are located.
Step 2 : Configure Selenium IDE
  • Open Selenium IDE
  • Go to Options
  • Click on Options menu
image
  • Selenium IDE options window is displayed and click on Webdriver tab.
image
  • Now check Enable Webdriver Playback options
  • Enter the full name of the browser you want to run your script in the text box below the checkbox. For example, in case of IE, we need to type “internet explorer”. In case of other browser, we can enter chrome, android, firefox, htmlunit, iPhone, iPad, opera.
image
  • Click ok button
  • Now restart the Selenium IDE. A restart is required to enable and disable webdriver. By default this option is disabled at selenium IDE.
Step 3 : Run Selenium Standalone server and Browser driver server
  • Before running this server ensure that java runtime environment is already installed on that machine as this is required to run JAR file. If not then download it from specific location.
  • Open the command prompt by using admin privilege (Run as administrator).
image
  • Go to the location where the Selenium Standalone server JAR file located. In my case, this is C:\Run location.
image
  • If you want to run your script on Internet explorer then type following command where both Selenium Standalone server and IE driver will start running.
java -jar selenium-server-standalone-2.42.2.jar -Dwebdriver.ie.driver=IEDriverServer.exe
image

image
  • In case of chrome driver the command will be
java -jar selenium-server-standalone-2.42.2.jar -Dwebdriver.chrome.driver=chromedriver.exe
All of the cases the command syntax will be
java -jar seleniumStandaloneServerFileName.jar -Dwebdriver.BrowserName.driver=.BrowserDriverServerFileName.exe

Note that every time we run the selenium standalone server with the browser driver server.

Step 4 : Run Selenium IDE scripts
  • Open Selenium IDE.
  • Load the recorded script file.
  • Run the script.
  • Note that the browser will be pop up and start executing the script.
Selenium IDE script recorded through Firefox browser will now run through other browsers like Chrome, IE etc.

Please comment me on any error you found to execute these steps.
Happy Cross Browser Testing!!!

Thursday, August 14, 2014

Easy way to determine the better XPath for Selenium Webdriver scripts

Determine the best XPath for selenium webdriver is sometimes difficult. We use different tools like Fire Bug, XPath checker, XPath Hepler for Chrome, developer tools for different browser etc. But determine the accurate XPath which will work every time when scripts runs, is sometimes difficult. It is found that proper XPath has constructed using a tool and implemented in the script to find the element and run the script multiple times at the time of development so that no “element not found” found but at the time of test execution it cannot detect the element. In that case we need to change the XPath again and run again to check that it is working.
But if we use the XPath that is  nearly better and developed by some of the Selenium tools like Selenium IDE, is more better than any other tools and nearly well known for Selenium webdriver API.
Here I will show you how to determine XPath for Selenium Webdriver scripts to locate element in the web page by using our well known Selenium IDE tools.

Installing the IDE tools:
You may know How to install Selenium IDE Plug in on your Firefox Browser. If not then click here.

Determining the XPath:
Step 1: Open Firefox browser.
Step 2: Click on the Selenium IDE icon on Plug in tool bar.

image

Step 3 : Selenium IDE window is displayed. Now click the red color record button to make the record on.

image

Step 4 : Now minimize the IDE window and enter the application URL : https://www.google.com.bd/ at the Firefox browser
Step 5 : Enter the text “Selenium IDE” at Google search text box and click on Search button.
Step 6 : Now Restore the Selenium IDE window and click red color button again to Stop the recording. You can play the script by clicking on green color play button.
Step 7 : Click on a Step. Command, Target and value is displayed at the bottom of the window.

 image

Step 8 : Here we see “id” as a locator in target combo box. If we click on the combo box we see a drop down list of other locators like Name, CSS, XPath etc.

image

Step 9 : There are three types of XPath here – Attribute, relative and Position. Most of the cases position is working fine. We select the XPath : Position at the target combo box. Now click on “Find” button to verify that it can locate the actual element.

image

Step 10 : Copy the XPath from Target box and paste to the selenium Webdriver code as Locator.
C# :
driver.FindElement(By.XPath("//td[2]/div/input")).SendKeys("Selenium IDE");
Java :
driver.findElement(By.xpath("//td[2]/div/input")).sendKeys("Selenium IDE");
Note that we will only use XPath if and only if id, Name or CSS are not available as locator. 
Thanks!!!

Monday, October 17, 2011

How to run Selenium WebDriver code with JUnit

In my previous post I have shown how to run Selenium WebDriver Code with NUnit.

Now I will show you how Selenium WebDriver code generated from selenium IDE can be run at JUnit4 Framework.

Selenium IDE has a functionality to convert its recorded script to Selenium WebDriver and Java in JUnit4 Framework.

So If we know how to record Selenium IDE (see the post : http://bit.ly/pa1TG5) then we can easily convert it to selenium WebDriver code.

Before starting we just define a Test case.

Test case :

    1. Open Selenium Website (http://seleniumhq.org/) in Firefox browser.
    2. Click Project tab
    3. Click Selenium IDE link
    4. Verify that Selenium IDE Text is present

Step 1: Record the test case in Selenium IDE

  • Open Firefox Browser
  • Open Selenium IDE window by Clicking Tools->Selenium IDE
  • Make Red colored Record button on.
  • Enter the URL : http://seleniumhq.org/ at the address bar and click Search button
  • Click Project tab
  • Click Selenium IDE link
  • Verify that Selenium IDE Text is present

The recorded script will be like the following figure

se9_thumb

Now make the record button off and Click Run button to run the script.

Step 2: Convert the Selenium IDE recorded script to JUnit 4 (WebDriver) code

  • Go to Selenium IDE window
  • Click Options menu
  • Click Format –> JUnit 4 (WebDriver)

se27

Sometimes in Options –> Format menu, JUnit 4 (WebDriver) options may not be displayed. The menu options like:

se13_thumb1

In that case, there is some change needed in selenium IDE option window. Please follow the steps:

  1. Click Options menu in Selenium IDE window
  2. Click “Options…” and Selenium IDE options window is displayed.

se12_thumb

se14_thumb1

Click Enable experimental features check box and click OK button. Now go to Format options and driver list.

  • A message dialog is displayed after selecting the appropriate format like (JUnit 4 (WebDriver))

se11_thumb

  • Click OK button
  • Selenium IDE window shows the selenium WebDriver Code in Java format with unit testing Framework JUnit 4 is implemented.

se28

 

Step 2: Run the Code in Eclipse IDE

  • Open Eclipse IDE
  • Create a New Java project by Clicking the options File –>New –>Java Project and New Java Project Window is displayed

se29

  • Enter Project name and select Project execution environment as JavaSE-1.6
  • Click Next button
  • Click Finish button
  • New Project is created
  • Add a New Java Class to the project
  • Now Copy the whole text from Selenium IDE and paste into New Java class file. It is like Copy the whole text like CTRL+A to select the whole text and CTRL+C to copy. 
  • There are some Reference error show at editor.
  • Right click on the project name and click Properties and Properties window is displayed

se30

  • Click Java Build path and click Libraries Tab
  • Click Add Library button

se31

  • Add Library window is displayed
  • Select JUnit and click Next
  • Select JUnit4 as JUnit Library and click Finish button
  • JUnit4 library is added and click OK button of properties window
  • Now go to selenium download page ( http://seleniumhq.org/download/ ) and download the latest version of Selenium Client Driver for Java.  Here version 2.8.0 is downloaded.

se33

  • Now unzip downloaded zip file and rename the folder as “Selenium” and placed to the Current project folder
  • Right click on the Project name in Eclipse and click Properties and properties window is displayed
  • Click Java Build Path
  • Go to Libraries tab and click Add External JARs

se34

  • Go to Selenium folder and select the jar file named “selenium-java-2.8.0.jar” and click Open. Selenium webdriver jar file is added

se35

  • Click OK button of Properties window
  • Remove the package name “package com.example.tests;”
  • Rename the Class name Untitled to Java Class file name

  • Add the following code at the testUntitled() method
Assert.assertEquals("Text Found", "Selenium IDE", driver.findElement(By.xpath("//div[@id='mainContent']/table/tbody/tr/td/p/b")).toString());


  • The method will be
public void testUntitled() throws Exception {
    driver.get("http://seleniumhq.org/");
    driver.findElement(By.linkText("Projects")).click();
    driver.findElement(By.linkText("Selenium IDE")).click();
    Assert.assertEquals("Text Found", "Selenium IDE", driver.findElement(By.xpath("//div[@id='mainContent']/table/tbody/tr/td/p/b")).toString());
  }
 


  • The whole codes are

  1: 
  2: 
  3: import java.util.regex.Pattern;
  4: import java.util.concurrent.TimeUnit;
  5: 
  6: import junit.framework.Assert;
  7: import junit.framework.AssertionFailedError;
  8: 
  9: import org.junit.*;
 10: import static org.junit.Assert.*;
 11: import static org.hamcrest.CoreMatchers.*;
 12: import org.openqa.selenium.*;
 13: import org.openqa.selenium.firefox.FirefoxDriver;
 14: import org.openqa.selenium.support.ui.Select;
 15: 
 16: public class testSel {
 17:   private WebDriver driver;
 18:   private String baseUrl="";
 19:   private StringBuffer verificationErrors = new StringBuffer();
 20:   @Before
 21:   public void setUp() throws Exception {
 22:     driver = new FirefoxDriver();
 23:     driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
 24:   }
 25: 
 26:   @Test
 27:   public void testUntitled() throws Exception {
 28:     driver.get("http://seleniumhq.org/");
 29:     driver.findElement(By.linkText("Projects")).click();
 30:     driver.findElement(By.linkText("Selenium IDE")).click();
 31:     Assert.assertEquals("Text Found", "Selenium IDE", driver.findElement(By.xpath("//div[@id='mainContent']/table/tbody/tr/td/p/b")).toString());
 32:   }
 33:   @After
 34:   public void tearDown() throws Exception {
 35:     driver.quit();
 36:     String verificationErrorString = verificationErrors.toString();
 37:     if (!"".equals(verificationErrorString)) {
 38:       fail(verificationErrorString);
 39:     }
 40:   }
 41: 
 42:   private boolean isElementPresent(By by) {
 43:     try {
 44:       driver.findElement(by);
 45:       return true;
 46:     } catch (NoSuchElementException e) {
 47:       return false;
 48:     }
 49:   }
 50: }
 51: 


  • Now Run project by click Run button from JUnit4

se34



  • Firefox Browser is opened and Script runs and Test is successful.

That’s all. I have described here all the steps in a very easy and details way. If any thing could not be understand, please comment me, I must answer. Please comment me about the whole blog.

Tuesday, September 20, 2011

How to run Selenium Webdriver code with Visual Studio Test Framework

 

Previous Post, I have shown you how to run selenium WebDriver code in Visual Studio with NUnit Framework.

Now I will show you how Selenium WebDriver code generated from selenium IDE can be run at Visual studio Test Framework.

Selenium IDE has a functionality to convert its recorded script to Selenium WebDriver and C# in NUnit Framework. Here we copy some portion of code and paste it to Visual studio test framework

So If we know how to record Selenium IDE (see the post : http://bit.ly/pa1TG5) then we can easily convert it to selenium WebDriver code.

Before starting we just define a Test case.

Test case :

    1. Open Selenium Website (http://seleniumhq.org/) in Firefox browser.
    2. Click Project tab
    3. Click Selenium IDE link
    4. Verify that Selenium IDE Text is present

Step 1: Record the test case in Selenium IDE

  • Open Firefox Browser
  • Open Selenium IDE window by Clicking Tools->Selenium IDE
  • Make Red colored Record button on.
  • Enter the URL : http://seleniumhq.org/ at the address bar and click Search button
  • Click Project tab
  • Click Selenium IDE link
  • Verify that Selenium IDE Text is present

The recorded script will be like the following figure

se9_thumb

Now make the record button off and Click Run button to run the script.

Step 2: Convert the Selenium IDE recorded script to C# WebDriver code

  • Go to Selenium IDE window
  • Click Options menu
  • Click Format –> C#(WebDriver).

se10_thumb2

Sometimes in Options –> Format menu, C#(WebDriver) options may not be displayed. The menu options like:

se13_thumb[1]

In that case, there is some change needed in selenium IDE option window. Please follow the steps:

  1. Click Options menu in Selenium IDE window
  2. Click “Options…” and Selenium IDE options window is displayed.

se12_thumb

se14_thumb1

Click Enable experimental features check box and click OK button. Now go to Format options and driver list.

  • A message dialog is displayed after selecting the appropriate format like (C#(WebDriver))

se11_thumb

  • Click OK button
  • Selenium IDE window shows the selenium WebDriver Code in C# format with unit testing Framework NUnit is implemented.

se15_thumb3

Step 2: Run the Code in visual Studio 2010 Test Framework

  • Open Visual Studio 2010 IDE
  • Create a Test Project by Clicking Test->New Test. A Test project is created with a default class name UnitTest1.cs
  • Double click on UnitTest1.cs on Solution Explorer to open the class file

se25

  • Now go to Selenium IDE code editor and find the method name “TheUntitledTest()”
  • Copy the entire code of this method and paste to “TestMethod1()” method of VS Test project and the method “TestMethod1()” looks like the following

 

public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            driver.Navigate().GoToUrl(baseURL);
            driver.FindElement(By.LinkText("Projects")).Click();
            driver.FindElement(By.LinkText("Selenium IDE")).Click();
            // ERROR: Caught exception [ERROR: Unsupported command [isTextPresent]]
        }
    }

 

  • Now Add two selenium namespace

 

  1. using OpenQA.Selenium;
  2. using OpenQA.Selenium.Firefox;

 

  • Now go to selenium download page ( http://seleniumhq.org/download/ ) and download the latest version of Selenium Client Driver with C#. Here version 2.6.0 is downloaded.

se17_thumb3

  • Now unzip downloaded zip file and rename the folder as “Selenium”
  • Go to Solution explorer of Visual Studio IDE
  • Right click Reference and click Add Reference option. Add Reference window is displayed

se19_thumb1

  • Click Browse tab and go to Selenium folder. Inspect that there are 2 sub folder – net35 and net40. net35 folder is for .Net framework 3.5 project and net40 for .Net framework 4.0 project. In this project .Net framework 4.0 is selected so we go to net40 folder
  • Select all the dlls and click OK button and .dll files are added as reference

se20_thumb3

 

  • Now all the references are added
  • Go to “public void TestMethod1()” method
  • Create Firefox Driver object named “driver” and the code will be
FirefoxDriver driver = new FirefoxDriver();
  • Add a string variable for base URL named “baseURL”.  Code looks like
string baseURL = "http://seleniumhq.org/";

 

  • Add the following code at the TestMethod1() method for verification

Assert.AreEqual(driver.FindElement(By.XPath("//div[@id='mainContent']/table/tbody/tr/td/p/b")).Text, "Selenium IDE");
  • For closing the browser window add the code at last line
driver.Close();
  • Here is the total code for VS Test
      using System;
      using System.Text;
      using System.Collections.Generic;
      using System.Linq;
      using Microsoft.VisualStudio.TestTools.UnitTesting;
      using OpenQA.Selenium;
      using OpenQA.Selenium.Firefox;

      namespace TestProject1
      {
          [TestClass]
          public class UnitTest1
          {
              [TestMethod]
              public void TestMethod1()
              {
                  FirefoxDriver driver = new FirefoxDriver();
                  string baseURL = "http://seleniumhq.org/";
                  driver.Navigate().GoToUrl(baseURL);
                  driver.FindElement(By.LinkText("Projects")).Click();
                  driver.FindElement(By.LinkText("Selenium IDE")).Click();
                  Assert.AreEqual(driver.FindElement(By.XPath("//div[@id='mainContent']/table/tbody/tr/td/p/b")).Text, "Selenium IDE");
                  driver.Close();
              }
          }
      }
       
      • Build the solution by right clicking on the solution name and Click build solution
      • Inspect that no Error message is displayed and build is succeeded.
      • Click Run button
      • Firefox Browser is opened and Script runs and Test is successful.

      se26

      That’s all. I have described here all the steps in a very easy and details way. If any thing could not understand, please comment me, I must answer.

      In my next Selenium blog, I will show how we can run our selenium WebDriver code in Java with JUnit4 Framework.

    • Monday, September 19, 2011

      How to run Selenium WebDriver code with NUnit

       

      In the last post I have shown you how to record and play back with Selenium IDE.

      Now I will show you how Selenium WebDriver code generated from selenium IDE can be run at visual studio 2010 with NUnit Framework.

      Selenium IDE has a functionality to convert its recorded script to Selenium WebDriver and C# in NUnit Framework.

      So If we know how to record Selenium IDE (see the post : http://bit.ly/pa1TG5) then we can easily convert it to selenium WebDriver code.

      Before starting we just define a Test case.

      Test case :

        1. Open Selenium Website (http://seleniumhq.org/) in Firefox browser.
        2. Click Project tab
        3. Click Selenium IDE link
        4. Verify that Selenium IDE Text is present

       

      Step 1: Record the test case in Selenium IDE

      • Open Firefox Browser
      • Open Selenium IDE window by Clicking Tools->Selenium IDE
      • Make Red colored Record button on.
      • Enter the URL : http://seleniumhq.org/ at the address bar and click Search button
      • Click Project tab
      • Click Selenium IDE link
      • Verify that Selenium IDE Text is present

      The recorded script will be like the following figure

      se9

      Now make the record button off and Click Run button to run the script.

      Step 2: Convert the Selenium IDE recorded script to C# WebDriver code

      • Go to Selenium IDE window
      • Click Options menu
      • Click Format –> C#(WebDriver).

      se10

      Sometimes in Options –> Format menu, C#(WebDriver) options may not be displayed. The menu options like:

      se13

      In that case, there is some change needed in selenium IDE option window. Please follow the steps:

      1. Click Options menu in Selenium IDE window
      2. Click “Options…” and Selenium IDE options window is displayed.

      se12

      se14

      Click Enable experimental features check box and click OK button. Now go to Format options and driver list.

       

      • A message dialog is displayed after selecting the appropriate format like (C#(WebDriver))

      se11

      • Click OK button
      • Selenium IDE window shows the selenium WebDriver Code in C# format with unit testing Framework NUnit is implemented.

      se15

       

      Step 2: Run the Code in visual Studio 2010

      • Open Visual Studio 2010 IDE
      • Create a New Class Library project by Clicking the options  File –>New –>Project and New Project Window is displayed
      • Select Visual C# from the template and project type Class Library

      se16

      • Enter Project name, Location and Solution Name and Select .Net Framework 4.0
      • Click OK button
      • New Project is created
      • Now Copy the whole text from Selenium IDE and paste into Class Library project editor. It is like Copy the whole text like CTRL+A to select the whole text and CTRL+C to copy. Then remove all sample code from VS editor  and Paste CTRL+V to all code.
      • There are some Reference error show at editor. It could not find Open QA namespace. For this we need some .dll file from Selenium client driver to add as a reference.

      se18

      • Now go to selenium download page ( http://seleniumhq.org/download/ ) and download the latest version of Selenium Client Driver with C#. Here version 2.6.0 is downloaded.

      se17

      • Now unzip downloaded zip file and rename the folder as “Selenium”
      • Go to Solution explorer of IDE
      • Right click Reference and click Add Reference option. Add Reference window is displayed

      se19

      • Click Browse tab and go to Selenium folder. Inspect that there are 2 sub folder there – net35 and net40. net35 folder is for .Net framework 3.5 project and net40 for .Net framework 4.0 project. If the class library project is created as ,Net framework 3.5 then we select the .dll file of net35 folder. In this project .Net framework 4.0 is selected so we go to net40 folder
      • Select all the dlls  and click OK button and .dll files are added as reference

      se20

       

      • Now NUnit dll’s are needed for NUnit framework
      • Now download the latest NUnit form the site (http://www.nunit.org/index.php?p=download)
      • Download the latest NUnit with windows verison (2.5.10) and Install
      • Now right click on Reference and click Add Reference and go to NUnit folder where it is installed like (C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\framework)
      • Select (nunit.framework.dll) file and click OK

      se21

      • Now all the references are added
      • Add the following code at the TheUntitledTest() method
      Assert.AreEqual(driver.FindElement(By.XPath("//div[@id='mainContent']/table/tbody/tr/td/p/b")).Text, "Selenium IDE");
      • TheUntitledTest() method will be
      1. public void TheUntitledTest()
      2.       {
      3.           driver.Navigate().GoToUrl(baseURL);
      4.           driver.FindElement(By.LinkText("Projects")).Click();
      5.           driver.FindElement(By.LinkText("Selenium IDE")).Click();
      6.           Assert.AreEqual(driver.FindElement(By.XPath("//div[@id='mainContent']/table/tbody/tr/td/p/b")).Text, "Selenium IDE");
      7.           // ERROR: Caught exception [ERROR: Unsupported command [isTextPresent]]
      8.       }

       

      • Class1.cs code (whole WebDriver code) will be
      1. using System;
      2. using System.Text;
      3. using System.Text.RegularExpressions;
      4. using System.Threading;
      5. using NUnit.Framework;
      6. using OpenQA.Selenium;
      7. using OpenQA.Selenium.Firefox;
      8.  
      9. namespace SeleniumTests
      10. {
      11.     [TestFixture]
      12.     public class Untitled
      13.     {
      14.         private IWebDriver driver;
      15.         private StringBuilder verificationErrors;
      16.         private string baseURL;
      17.  
      18.         [SetUp]
      19.         public void SetupTest()
      20.         {
      21.             driver = new FirefoxDriver();
      22.             baseURL = "http://seleniumhq.org/";
      23.             verificationErrors = new StringBuilder();
      24.         }
      25.  
      26.         [TearDown]
      27.         public void TeardownTest()
      28.         {
      29.             try
      30.             {
      31.                 driver.Quit();
      32.             }
      33.             catch (Exception)
      34.             {
      35.                 // Ignore errors if unable to close the browser
      36.             }
      37.             Assert.AreEqual("", verificationErrors.ToString());
      38.         }
      39.  
      40.         [Test]
      41.         public void TheUntitledTest()
      42.         {
      43.             driver.Navigate().GoToUrl(baseURL);
      44.             driver.FindElement(By.LinkText("Projects")).Click();
      45.             driver.FindElement(By.LinkText("Selenium IDE")).Click();
      46.             Assert.AreEqual(driver.FindElement(By.XPath("//div[@id='mainContent']/table/tbody/tr/td/p/b")).Text, "Selenium IDE");
      47.             // ERROR: Caught exception [ERROR: Unsupported command [isTextPresent]]
      48.         }
      49.         private bool IsElementPresent(By by)
      50.         {
      51.             try
      52.             {
      53.                 driver.FindElement(by);
      54.                 return true;
      55.             }
      56.             catch (NoSuchElementException)
      57.             {
      58.                 return false;
      59.             }
      60.         }
      61.     }
      62. }
      • Build the solution by right clicking on the solution name and Click build solution
      • Inspect that no Error message is displayed and build is succeeded.
      • Now open NUnit application editor by going Start – > Program – > NUnit 2.5.10 –> NUnit
      • Now go to File – > Open Project
      • Select the Class Library dll file from bin/debug folder of Class Library project
      • Click Run button
      • Firefox Browser is opened and Script runs and Test is successful.

      se24

      That’s all. I have described here all the steps in a very easy and details way. If any thing could not be understand,  please comment me, I must answer. Please comment me about the whole blog.

      In my next blog, I will show how we can run our selenium WebDriver code in Visual Studio Test Framework.

      Cypress: How to handle browser-based authentication pop up dialog in Cypress

      Five years ago I have written a blog on how to handle browser-based authentication for selenium webdriver.   Now it is for cypress. Cypress...