Sunday, February 14, 2016

Selenium : Simple Error Reporting in TestNG without Halt (Soft assertion)

 Simple Error Reporting in TestNG without Halt (Soft assertion)

 Following Class in TestNG offers reporting :
1. Soft Assertion : Execution will not skip the rest of the steps in  the method.
 SoftAssert soft_assert=new SoftAssert();  
 soft_assert.assertEquals("abc", "ABC");
 soft_assert.assertAll(); //should be added in all @Test Methods
2. Hard Assertion :Execution will skip rest of the steps in the method and move to the next method
Assert.assertEquals("abc", "ABC");

3. To log the information from the script to the HTML report we must use the class org.testng.Reporter
Now to print the data to the report we must use :
Reporter.log("PASS/FAIL");
-------------------------------------------------------------------------------------

 Project Tree



// Assert1.java

import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;

public class Assert1 {
    SoftAssert soft_assert=new SoftAssert();
       
    @Test
    public void test1(){               
        Assert.assertEquals("abc", "ABC");
        System.out.println("hi");       
    }
   
    @Test
    public void test2(){               
        soft_assert.assertEquals("abc", "ABC");
        System.out.println("bye");
        soft_assert.assertAll();       
    }
}

//testng.xml

<suite name="TestNg_test">       
       <test name="assert1">>        
              <classes>
                     <class name="Assert1" />                     
              </classes>
       </test>       
</suite>

Thursday, February 11, 2016

Java : "String[] args" arguement in Main Method



public static void main(String [] args)

Those are for command-line arguments in Java.
In other words, if you run
java MyProgram one two
Then args contains:
[ "one", "two" ]
public static void main(String [] args) {
   String one = args[0]; //=="one"
   String two = args[1]; //=="two"
}
The reason for this is to configure your application to run a particular way or provide it with some piece of information it needs.

Thursday, November 19, 2015

vbs - Invert Mouse wheel


 Invert Mouse wheel



Call test()
msgbox("Done!! Please restart to take effect")


Sub test()
  Set objShell = CreateObject("Wscript.Shell")
 'objShell.Run ("powershell.exe -noexit write-host Hello world -exit")
 'objShell.Run ("powershell.exe -noexit Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device` Parameters FlipFlopWheel -EA 0")
 objShell.Run ("powershell.exe -noexit Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device` Parameters FlipFlopWheel -EA 0 | ForEach-Object { Set-

ItemProperty $_.PSPath FlipFlopWheel 1 }")
End Sub

'View registry path
'Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device` Parameters FlipFlopWheel -EA 0

'Change registry settings
'Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device` Parameters FlipFlopWheel -EA 0 | ForEach-Object { Set-ItemProperty $_.PSPath FlipFlopWheel 1 }

'Restore
'Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device` Parameters FlipFlopWheel -EA 1 | ForEach-Object { Set-ItemProperty $_.PSPath FlipFlopWheel 0 }

Wednesday, September 9, 2015

Selenium : Change execution speed in Java (Set Speed)

Change execution speed in Java (Set Speed)

 

Create a new class "_WebDriver" which extends FireFoxDriver. Inside  "_WebDriver" class override method "findElement" and introduce a delay inside it.

public class Main_class{
    public static void main(String[] args)
    {
              WebDriver driver=new _WebDriver(200);
            
               driver.get("https://in.yahoo.com/");
               driver.findElement(By.id("UHSearchBox")).sendKeys("address1");    
              driver.findElement(By.id("UHSearchWeb")).click();
    }
}
 
//---------Create a new Java File
public class _WebDriver extends FirefoxDriver {
 
     private int set_speed=0;

    
     public _WebDriver(int set_speed)
//Constructor to initialize the speed
{
         this.set_speed=set_speed;
     }

    @Override
    public WebElement findElement(By by) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return by.findElement((SearchContext) this);
    }
}

Selenium : Passing Arguements using "By" class

Passing locator Arguments using "By" class


Passing locator in Selenium before its existence .(small snippet below)

class base_Library{

public static void main(String args[])

{
    Lib base_Library=new base_Library();
    base_Library.wait_to_load(By.id("templateCombobox"));
}

public void wait_to_load(By by){
        WebDriverWait wait = new WebDriverWait(driver,10);        wait.until(ExpectedConditions.elementToBeClickable(by));
    }
}




Selenium : Using FireFox and Chrome inbuilt Inspector and Xpath evaluator


Using FireFox inbuilt Inspector and Xpath evaluator

Steps below

  1. Launch Firefox (I'm using  40.0.3)
  2.  Open url "google.co.in"
  3. Goto Tools >Web Developer>Inspector
 

 Similar to Firebug , user can use crosshair in the console to target a particular element.

To Verify Xpath :
  1. In the above console
  2. Click on ">Console" tab
  3. type - $x("//input[@type='submit']")
  4. Press "Enter"
 


Syntax : $x("xpath")

For Chrome (same as Firefox)

Method 1:
Install Chropath extension for Chrome
Rt ck on web page
Ck on inspect 
In Developer window , click on ">>" symbol
Select chropath



Method 2 :
User can goto :
  • Settings>More tools >Developer tools
  • Elements > Control+F  to open search box
  • Type in your xpath Eg : .//input[@type='password']
OR
  • User can also validate Xpath using "Console" tab similar to FireFox
Rest is same as FireFox.

You can also try:

  1. Press F12 to open Chrome Developer Tool
  2. In "Elements" panel, press Ctrl+F
  3. In the search box, type in XPath or CSS Selector, if elements are found, they will be highlighted in yellow.