Wednesday, July 9, 2014

Git useful commands

I'll present some useful tips on using GIT commands which are helpful at times. GIT is popular SCM (source code management system). It was initially designed by Linus Torvalds. Unlike other SCMs GIT working directory in itself is full fledged repository

# Merge selective commit
If you have multiple branches in your repository and there are set of commits applied at one branch 
, e.g., Branch1
  • changes for web.config (commit no: ediekd3839929293)
  • changes for db (commit no: gdjsk29182kdlk)
Now you want to merge code change for db (gdjsk29182kdlk) in Branch2.
 
Then first goto Branch2
  • git checkout Branch2
Merge changes from commit no/hash that you want , e.g.,  
  • git cherry-pick gdjsk29182kdlk
# Create new branch like exisiting one
git checkout -b <branch name>
 
# To create empty branch
git branch --orphan <branchname>
 
# Undo unstaged changes
git reset --hard
Note: be cautious this it'll reset unstaged changes in the repository, so use this when you're really sure
 
# There are some cool features that you can leverage at Unix/Linux terminal by concatenating multiple commands 
&& Combine two commands to execute in single line , e.g.,
  • git reset --hard && git checkout -b newbranch1
 It'll first reset all unstaged changes and then create newbranch1 like current branch
 
GIT is fantastic tool, incase you've any query then reach out to me @sumitjolly (twitter) 

Saturday, March 3, 2012

Automation Testing

In VS, how to write automate test cases through Selenium:
  1. Download file "selenium-dotnet-2.20.0.zip" from https://code.google.com/p/selenium/downloads/detail?name=selenium-dotnet-2.20.0.zip&can=2&q=
  2. Unzip files and place it in new folder say 'Selenium'
  3. Download NUnit (www.nunit.org/) and TestDriven (http://testdriven.net/download.aspx) and install it
  4. Create new C# project in VS2010
  5. Add References of dll files unzipped in step 2, say Webdriver etc.
  6. Add Reference of Nunit.framework
  7. Include namespaces accordingly in you CS file
using System;
using System.Threading; //include namespace (NS)
using NUnit.Framework; //add reference and include NS
using OpenQA.Selenium; //add reference and include NS
using OpenQA.Selenium.Firefox; //add reference and include NS
namespace Project1
{

    [TestFixture]
    public class CTD 
    {
        private IWebDriver _driver;// = new FirefoxDriver();
        
        [SetUp]
        public  void Init()
        {
            _driver = new FirefoxDriver(); //you can use InternetDriver for IE
            _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(100)); 
            //seconds you can define maximum time of any event to be executed so test shouldn't fail
        }
        [Test]
        public void TestCase1()
        {
            _driver.Navigate().GoToUrl("http://localhost:xxxxx/abc.aspx"); 
            //replace your localhost portno and mention startpage for test
           IWebElement query = _driver.FindElement(By.Id("txtFName)); 
           //Find element on webpage
          query.SendKeys("Sumit Jolly"); //fills data in textbox
          Assert.AreEqual ("Sumit Jolly", _driver.FindElement(By.Id("txtFName))); 
          //Test whether data entered by you is right
         _driver.FindElement(By.Id("btnSubmit")).Click();
        }
        [Test]
        public void TestCase2()
        {
        }
        [TearDownAttribute]
        public  void Clean()
        {
            Thread.Sleep(1000); //milliseconds
            // TODO add wait
            _driver.Quit();
        }
    }
}