Friday, November 21, 2014

Vbs: Reflection in vbs or Converting String into Function Name

  Reflection in vbs or Converting String into Function Name



Output:
tc1
tc2

SQL :Important Queries

SQL Server : Important Queries


1.To display all tables in a database
SELECT * FROM information_schema.tables
 
2. To display table information
 sp_help table_name

Tuesday, November 18, 2014

TestComplete : UserForms

TestComplete : UserForms





Dim sPath,sBrowser,oDialog,form,mr

sub a
    Set form = UserForms.UserForm1
    Set oDialog = form.OpenDialog1        
     
      do
        mr=form.ShowModal     'Show GUI
        Select Case mr
            Case mrOK          'Ok button , In properties set the ModalResult as mrOK 
           
                   if( (form.cxRadioGroup1.ItemIndex=0 or form.cxRadioGroup1.ItemIndex=1) and sPath<>"" )then
                      if(form.cxRadioGroup1.ItemIndex=0) then
                        sBrowser="FireFox"
                        else
                        sBrowser="IE"
                      end if   
                      exit do
                   end if
                             
            Case mrCancel     'Cancel Button .'Ok button , In properties set the ModalResult as mrCancel      
                  exit sub
                     
             Case mrYes         'BrowserButton , In properties set the ModalResult as mrYes
                     oDialog.Execute           'Trigger TOpenBrowser
                     sPath=oDialog.FileName
                     form.Path.Text=sPath
      End Select
    Loop  While (1<2)
   
    msgbox("Browser="&sBrowser&vblf&"File Path="&sPath)
     
end sub

Saturday, November 15, 2014

Android : Cannot resolve android (Android Studio error)

Cannot resolve android  (Android Studio error)


Make sure you have Andoid SDK in your system :

1- press ctrl+alt+shift+s
2-in the Modules bar click on your project name
3-change the compile sdk version to the newest one
4-click apply and ok then sync your project
5-done , i hope the best for you

Thursday, November 13, 2014

Eclipse: Paste Multiline String

Paste Multiline String


Eclipse has an option so that copy-paste of multi-line text into String literals will result in quoted newlines:


Preferences/Java/Editor/Typing/  enable Escape text when pasting into a string literal"



Wednesday, November 12, 2014

Selenium : Eclipse (java) relative path

Eclipse (java) relative path



Example  1:
String filePath = ".\\images\\NotSet_16x16.png";

Example 2 :
If I have a project with following structure and want to reach excel file "excel.xls" as below .


Project_test
        |
        |
         --- src
            |
            |
             ---com (this is a package)
                |
                |
                ---    library (this is a package)
                    |
                    |
                    ---excel.xls



Path=".\\src\\com\\library\\excel.xls"


where «.\» is a root for Eclipse project, «images» is a folder with user's files inside of Eclipse project. Since we are talking about Windows OS, we have to use «\» and not «/», like in Linux, but «\» is the reserved symbol, so we have to type «\» to get desired result.

Monday, November 10, 2014

Selenium : 2D listin Java

2D list in Java

 

// Create an ArrayList of ArrayLists of Integers
ArrayList<ArrayList<Integer>> my2DArrayList = new ArrayList<ArrayList<Integer>>();
// add in a few ArrayLists. These contain the "rows" of the 2D ArrayList
my2DArrayList.add(new ArrayList<Integer>());
my2DArrayList.add(new ArrayList<Integer>());
my2DArrayList.add(new ArrayList<Integer>());
// you can retrieve rows using get(), then treat that 1D arrayList as the column.
my2DArrayList.get(0).add(1);
my2DArrayList.get(0).add(2);
my2DArrayList.get(1).add(3);
my2DArrayList.get(1).add(4);
my2DArrayList.get(1).add(0);
my2DArrayList.get(2).add(5);
// my2DArrayList now contains this:
// row 0: 1, 2
// row 1: 3, 4, 0
// row 2: 5
// to retrieve a specific element, you need to first get the ArrayList of the row you want, then retrieve the column from that arraylist you want
// get element at row 1 and column 2
int number = my2DArrayList.get(1).get(2);


Friday, November 7, 2014

Selenium : TestNg Dataprovider with DependsonMethod

TestNg Dataprovider with DependsonMethod

public class testng {
       
    @DataProvider
        public Object[][] dp() {
          Object[][] o=new Object[2][2];
          o[0][0]="a";
          o[0][1]="b";
          o[1][0]="c";
          o[1][1]="d";
          return o;
        }
   
    @Test()
    public void a1()
    {
        System.out.println("byei");
    }
   
    @Test(dependsOnMethods= { "a1" },dataProvider="dp")
    public void a2(String a,String b)
    {
        System.out.println(a+b);
    }   
}

 

Output 

byei
ab
cd

Selenium : Retrieve Method information in Testng DataProvider

Retrieve Method information in Testng DataProvider


If you declare your @DataProvider as taking a java.lang.reflect.Method as first parameter, TestNG will pass the current test method for this first parameter. This is particularly useful when several test methods use the same @DataProvider and you want it to return different values depending on which test method it is supplying data for.

For example, the following code prints the name of the test method inside its @DataProvider:

@DataProvider(name = "dp")
public Object[][] createData(Method m) {
  System.out.println(m.getName());  // print test method name
  return new Object[][] { new Object[] { "Cedric" }};
}

@Test(dataProvider = "dp")
  public void test1(String s) {
}

@Test(dataProvider = "dp")
  public void test2(String s) {
}


and will therefore display:

test1
test2

Selenium:TestNG factory class with example

TestNG factory class with example 

 http://roadtoautomation.blogspot.in/2014/08/testng-factory-class-with-example.html


@DataProvider is used to pass different test data to a test method
@Factory is used to create different instance of Test class and is useful annotation when you run test multiple time.
you can find examples with description for both at : http://testng.org/doc/index.html


DataProvider Example:

public class DataProviderDemo {

    @DataProvider(name="myDataProvider")
    public Object[][] data(){
        return new Object[][]{ {"adf",5.0f}, {"dfds",4.0f} };
    }
    
    @Test(dataProvider="myDataProvider")
    public void method1( String strData ,float floatData){
        Reporter.log("String "+strData);
        Reporter.log("float "+floatData);
    }
  
}


Factory Example:

public class FactoryDemo {
   
    String strData;
    float floatData;
   
    public FactoryDemo(String string, float f){    
        strData = string;
        floatData = f;      
    }
   
    @Factory
    public static Object[] data(){
        return new Object[]{  new FactoryDemo("adf",5.0f),  new FactoryDemo("dfds",4.0f)   };
    }
      
    @Test()
    public void method1(){
        Reporter.log("String "+strData);
        Reporter.log("float "+floatData);
    }  
}

Selenium : Using 2 Dataproviders in single test

Selenium : Using 2 Dataproviders in single test


public class testng {
 
 public Object[][] dp1() {
    return new Object[][] {new Object[] { "a", "b" },new Object[] { "c", "d" } };
  }

  public Object[][] dp2() {
    return new Object[][] {  new Object[] { "e", "f" },new Object[] { "g", "h" } };
  }

  @DataProvider
  public Object[][] dp() {
    List result = Lists.newArrayList();
    
    result.addAll(Arrays.asList(dp1()));
    result.addAll(Arrays.asList(dp2()));
    return result.toArray(new Object[result.size()][]);
    
  }

  @Test(dataProvider = "dp")
  public void f(String a, String b) {
    System.out.println( a + " " + b);

  }

}//

Selenium : Testng not running Test Cases

Selenium : Testng not running Test Cases


In the below screenshot , the Testng will executethe test case "m1 ()"



The problem is that all the methods which use Testng annotationsshould be declared " public "  by default :


Tuesday, November 4, 2014

Selenium:Create firefox profile with addons and preferences

Selenium:Create firefox profile with addons and preferences

 

Note : If you already have a profile with Firebug added then use :
System.setProperty("webdriver.firefox.profile", "default");
//to find profile name - Start>Run >firefox -ProfileManager

1. Close all firefox instances ,verify the same if any firefox instance is running in the task manager.
2. Goto Start>Run and type "firefox -ProfileManager"
3. click "OK"
4. Firefox "Choose profile" should open.
5. Click on "Create Profile"button.
6. Click on next button in following screen
7. Enter profile name in the next screen and choose the path where you want to save it (ex. D:\profile)
8. Click on finish.
9.  Now uncheck "use the selected profile without asking at startup"
10. Select the profile which has been created .
11 click on "Start firefox ".

Now the firefox will be open with the selected profile.

12. Do required settings and add any addons needed and restart firefox.
13. Now when firefox opens check "use the selected profile without asking at startup"
14. Select default profile.
15 Click on "Start Firefox".


In your Selenium use the below code :

File profileDir = new File("D:\\profile");  //("path/to/top/level/of/profile");
FirefoxProfile profile = new FirefoxProfile(profileDir);
profile.setPreferences(extraPrefs);
WebDriver driver = new FirefoxDriver(profile);

Sunday, November 2, 2014

Selenium :Sikuli for 64Bit JRE- Solution

Selenium :Sikuli for 64Bit Machine - Solution


If you are using Sikuli for the first time please refer the below link (once done we will port it to 64Bit)  :



Porting for 64Bit :
  1.   Download and install 32Bit JRE (http://filehippo.com/download_jre_32/3868/) .Make sure JRE 6 is installed in a different location to avoid conflicts.
  2. Open Eclipse and configure the following
a)      Project ---> Properties ---> Java Compiler : set compliance level and Source compatibility to 1.6
b)       Project ---> Properties ---> Java Build Path ---> Libraries ---> and change the JRE system library to 1.6
  1. Project ---> Java Build Paths--->Libraries--->Add Library--->Select Jre System Library
a)      Click Next
b)      Select Alternate JRE Radio button in JRE System Library Screen
c)      Click on Installed JREs
d)     In Prefrences window , Click on Search Button
e)      In search window , Select the Parent folder where Java6 is installed(“C:\Program Files (x86)\Java”)    .
f)       Click on OK
  1. Now Jre6 will be added to your Installed JREs window
  2. Now check “jre6” as default and close .
  3. Now check whether JRE6 has been added to your current project.

Now run your SIKULI script to check if the same is working .. .