Tuesday, 10 March 2015

C# bindings for Selenium

Prerequisites:
- Visual Studio is installed, click link for 'Visual Studio' installation.

1. Open the Visual Studio
 

2. Select the 'Console Application'.
    - Change the 'Name', 'Solution Name' and click on 'OK' button.


3. Download the Webdriver binding for C# language.
      - Open the URL: http://www.seleniumhq.org/download/
      - Click on 'Download' link for 'C#'.


 


4. Extract the downloaded zip file.


5. Add the webdriver dll's to the 'References'.
     - Right click and select 'Add Reference'.



6. Select all the webdriver related dll's and click on 'OK' button.


7. Webdriver dll's are added to the 'References'.

8. Add the code to launch the firefox browser and search for 'C#'.
    - Once code is added execute the program, clickto execute the program.

Sample Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace WDTest1
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.google.com");

            //Type C#
            driver.FindElement(By.Id("lst-ib")).SendKeys("C#");

            //Thread.sleep is used for initial/basic level coding,
            //In real time its better not to use 'Thread.sleep'.
            System.Threading.Thread.Sleep(2000);
            driver.FindElement(By.Name("btnG")).Click(); 

            System.Threading.Thread.Sleep(10000);

            driver.Close();
            driver.Quit();
        }
    }
}

9. Webdriver code is getting executed.

Environment used:
Above sample program is executed in below environment.
- Firefox browser version 33.0.1
- Windows 8 operating system.
- Microsoft Visual C# 2010 Express. 
- Selenium(Webdriver)-dotnet-2.45.0

Friday, 6 March 2015

C# - NUnit GUI Runner installation.

1. Open the URL: http://nunit.org/?p=download
    Click the link 'NUnit-2.6.4.msi' to download.
  

2. Click on 'NUnit-2.6.4.msi', which is downloaded.

3. Click on 'Next' button.

4. Accept the license aggrement and click on 'Next' button.

5. Click on 'Complete' button.

6. Click 'Install' button.

7. Installation is in progress.

8. Click 'Finish' button.

9. Open the NUnit GUI Runner.
    Note: Below screenshot shows launching NUnit GUI Runner in Windows 8 Operating System.

10. NUnit GUI Runner is opened.

C# - Nunit Script Creation and Execution

Prerequisites:
- Visual Studio is installed, click link for 'Visual Studio' installation .
- Nunit is installed, click link for 'NUnit GUI Runner' installation.

1. Open the Visual Studio

2. Select the Class Library.
   Enter Name and Solution Name.
   Click 'OK' button.

3. Class is created.

4. Expand 'References' in 'Solution Explorer'.


5. Mouse right click on 'References', select 'Add Reference'.

6. Select the 'Browse' tab, navigate to the folder where NUnit dll's are present.
    Select the dll's and click 'ok' button. 
          ex:C:\Program Files (x86)\NUnit 2.6.4\bin\framework


7. 'nunit.framework' is added in the 'References'.

8. Add Nunit attributes to the class, method and some assertion code to perform validation.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace NunitTest1
{
    [TestFixture]
    public class Class1
    {
        [TestCase]
        public void Test1()
        {
            int actualResults = 30;
            int expectedResults = 30;

            Assert.AreEqual(expectedResults, actualResults);
        }

    }
}

9. Build the solution.


10. Open the 'Nunit-GUI Runner' installed in your machine.


11. Select 'File' --> 'Open Project' in Nunit GUI Runner.

12. Select the project dll which is created at step 9 and click on 'Open' button.

13.  All the classes and methods marked by NUnit attributes are shown in the NUnit GUI Runner.

14. Select the method and click 'Run' button.
 
15. You can see the result as PASSED.

16. Now lets verify the failed results.
      Go to the code modify the Actual Results 30 to 40.

17. Rebuild the solution.

18. Go to Nunit GUI runner, now click on the 'Run' button again.

19. You can see the results as failed, since actualResults(40) and expectedResults(30) doesn't match.

Sunday, 15 February 2015

C#(Help Links) - Miscellaneous

C# - Miscellaneous


2. TeamCity for .NET Developers - 2 - Setup
Reference: https://www.youtube.com/watch?v=d8ZFeAdLyP4 

3. Troubleshooting - Exception 'microsoft.ace.oledb.12.0' provider is not registered on the local machine. in c#
- Try to download and install "2007 Office System Driver: Data Connectivity Components" this may solve the exception. 
Reference: http://www.microsoft.com/en-in/download/details.aspx?id=23734

4.Facing problem while opening Visual Studio solution, while opening .cs file or while trying to run it. Error message "No exports were found that match the constraint contract name"
Solution:
(%AppData%\..\Local\Microsoft\VisualStudio\11.0\ComponentModelCache)
Just rename or delete the Microsoft.VisualStudio.Default.cache file inside the above location.
 

5. Visual J# 
Reference: https://msdn.microsoft.com/en-us/library/7xsxf8e2%28v=vs.80%29.aspx 

6. C# Fundamentals for Absolute Beginners 
Reference: http://www.microsoftvirtualacademy.com/training-courses/c-fundamentals-for-absolute-beginners 

7. C# calling the method in the class using reflection api.
Reference: https://msdn.microsoft.com/en-us/library/a89hcwhh%28v=vs.110%29.aspx

Below sample program using reflection api is copied from above url
using System.Reflection;
public class TestMethodInfo
{
    public static void Main()
    {
        // Get the constructor and create an instance of MagicClass

        Type magicType = Type.GetType("MagicClass");
        ConstructorInfo magicConstructor = magicType.GetConstructor(Type.EmptyTypes);
        object magicClassObject = magicConstructor.Invoke(new object[]{});

        // Get the ItsMagic method and invoke with a parameter value of 100

        MethodInfo magicMethod = magicType.GetMethod("ItsMagic");
        object magicValue = magicMethod.Invoke(magicClassObject, new object[]{100});

        Console.WriteLine("MethodInfo.Invoke() Example\n");
        Console.WriteLine("MagicClass.ItsMagic() returned: {0}", magicValue);
    }
}
 
8. Java and AutoIT
Reference: 
https://code.google.com/p/autoitx4java/ 
http://www.joecolantonio.com/2014/07/02/selenium-autoit-how-to-automate-non-browser-based-functionality/
http://accessrichard.blogspot.in/2011/01/autoitx4java-java-autoit-bridge.html
 
9. Convert JSON Data Into Html Table Using Javascript JQuery
Reference: http://www.dotnetpickles.com/2014/04/json-to-html-table.html 
 

 

C# Help Links - Nunit

    C# Nunit Help Links

1. NUnit Test Application  download(based on NUnit console runner)
Reference: https://visualstudiogallery.msdn.microsoft.com/b8a7a8fa-9f5a-4b9b-8e8b-8839a4364f26

2. Install or set up Nunit framework in Visual Studio
Reference: https://www.youtube.com/watch?v=IdqUFuQDD34

3. Install or set up Selenium WebDriver with C# sharp and Nunit in Visual Studio
Reference: https://www.youtube.com/watch?v=QAHlp3DJh0M

4. Debugging NUnit Tests in Visual Studio 2010
Reference: http://codebrane.com/blog/2012/06/19/debugging-nunit-tests-in-visual-studio-2010/

5. Test Automation using C#, Selenium WebDriver and NUnit
Reference: https://anoopjshetty.wordpress.com/2012/02/08/creating-test-automation-framework-using-c-selenium-and-nunit/

6. How do I create and run NUnit/WebDriver test-suites.
References:
http://stackoverflow.com/questions/20285961/how-do-i-create-and-run-nunit-webdriver-test-suites-via-visual-studio
http://nunit.sourceforge.net/doc/cookbook/cookbook.html
http://www.autotestguy.com/archives/2006/05/nunit_quick_and.html
http://www.nunit.org/index.php?p=suite&r=2.6.3

7. Running NUnit tests programmatically
References:
https://fijiaaron.wordpress.com/2011/11/22/running-nunit-tests-programmatically/
https://gist.github.com/fijiaaron/1387474

8. Nunit Suite builder
Reference:
https://www.simple-talk.com/dotnet/.net-tools/testing-times-ahead-extending-nunit/

9. Run a test suite with NUnit GUI
Reference:
http://nbi.codeplex.com/wikipage?title=Run%20a%20test%20suite%20with%20NUnit%20GUI

10.Setup Jenkins on Windows and integrating it with NAnt.
Reference:
https://anoopjshetty.wordpress.com/2014/07/09/setup-jenkins-on-windows-and-integrating-it-with-nant/ 

11. NAnt Home Page.
Reference:

12. Xamarin Studio
Reference:
http://www.monodevelop.com/download/

Wednesday, 11 February 2015

C# - 'Hello World' Console Application program.

Click link for Visual C# installation procedure 

Launch Visual C# IDE.


Select 'New Project'.

Select 'Console Application' and click on 'OK' button.



Type 'Cons' and click keyboard 'Contrl' + 'Space' (Cntrl+Space) to see the available classes.


Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World");
            Console.ReadLine();
        }
    }
}

Executing the Program:

Output is displayed in console after executing the program.

Additional Information:
ConsoleApplication1.exe is generated.


Double click on 'ConsoleApplication1.exe' to execute exe file.
 
Executing .exe file doesn't require Visual C# IDE to be launched.