Most Viewed Pages

17.7.14

Configuring Eclipse and Selenium

There is a lot of stuff that you need to configure when you are working with selenium [depending on your needs] but the simplest would be to just have eclipse and selenium - that is all you need, everything else is just an add-on, for specific task\extension that you want to have.

    You would need to have the following bare minimum.
        1. Selenium jars [most populare being the java specific bindings]
        2. Eclipse
        3. Java Development Kit [JDK] - Ensure to point everything to JDK and not the JRE.
   
    Steps to configure selenium and eclipse -
       
  1. Configure Java by installing the latest version of the JDK [default setup - no customizations needed] and then, add the following Java Environment variables
            Path -
                ;C:\Program Files\Java\jdk1.7.0_10\bin;
               
            JAVA_HOME -
                C:\Program Files\Java\jdk1.7.0_10

            JDK_HOME -
                C:\Program Files\Java\jdk1.7.0_10

CLASSPATH (This is not needed anymore) -
               C:\Program Files\Java\jdk1.7.0_10\lib;

             If you get an output like below for java, then java is correctly configured.

 
         2. Download eclipse [any version and variant would do]
            - There is no installation needed to run eclipse, just put the extracted eclipse folder in the directory 'C:\ToolDirectory' and you are ready to run
       
        3. Download the selenium java bindings from the selenium HQ
            - Extract the zip and put that in the directory 'C:\ToolDirectory'. Lets follow a convention of naming the selenium folder like 'selenium-2.4.2'. Now place all the jar files under the selenium folder [there are usually 2 jar files that are extracted out in a seperate folder].
       
        4. Fire up eclipse
            - Create a new java project, like 'se-auto'
            - Under the src folder create folder structure like src\main\java and src\test\java
            - Associate all external selenium jars with the project
       
Thats all, you are all set!


Some DONTs -
  • Dont create a PATH var, but only Path - otherwise have seen issues with maven config
  • JAVA_HOME should not end with bin
  •  JAVA_HOME cannot have "\" or ";" in the end.
  • ";" should not be there at all
  • Ensure that the bit-architecture of the JDK and Eclipse is same - either both are 32-bit or both 64-bit - but not different. The OS bit-version can be anything, but now a days mostly everything is 64-bit, so ensure that you have the 64-bit trio for OS, JDK and Eclipse

Common Troubleshooting -
  • If you are still having issues, even after following the above steps correctly, first restart the machine before doing any more troubleshooting
  • View all Env Parameters - 
    • To view and dump all the Env params to a file use the following command on CMD:
      • set >> AllEnvParam.txt
    • To view all the Java Properties use: java -XshowSettings:properties -version
  • If you have installed the Java Add-in for QTP, then this can cause issues, and not let eclipse and other java dependent programs start. You may get an error that the JVM is incompatible or that the older version of java is not supported. If you don't need the Java Add-in, uninstall it, or remove the Env Variables that are being used.
  • Some of the other Env Variables like those below cause conflicts and can be delete
    • _JAVA_OPTIONS
    • IBM_JAVA_OPTIONS
    • JAVA_TOOL_OPTIONS
    • _classload_hook
  • If you have Oracle SQL Developer installed, then the Oracle JDK may be added to the JAVA_HOME Env param. Delete the value of the Oracle JDK from JAVA_HOME and ensure that only Java JDK is mentioned there, and nothing else.
  • If you have IntelliJ IDEA also installed, then point the 'IDEA_JDK' also to the JAVA_HOME
  • Error - 'Failed to load JNI shared library' - This occurs when the JDK and Eclipse have different bit-architectures. This can also be resolved by adding JAVA_HOME\bin to the start of the Path Variable. A very common resolution suggested for this is to specify the location of the javaw.exe in the eclipse.ini file, but it is not needed if we use the above approach.

Using different Firefox Profiles with Selenium WebDriver

By default, there is just one firefox profile [called 'default'] for a given user which is used everytime one opens firefox, but using this default profile may not be the best option when running webdriver scripts.
Hence, it is better to create a new profile specifically to be used just by the webdriver.
Although, there are more powerful and effective ways to manage firefox profiles and preferences with WebDriver, but the one below is simple and effective too, and is enough for most cases. The only hitch with this method is that you will have to manually create the same firefox profile on every computer that you want to run your tests

Steps to create a new firefox profile -

•    Close all open sessions of the firefox browser
•    Type the following command on the Run window - "firefox -ProfileManager"
•    Here you will see just one profile initially, the 'default' one
•    Create a new profile and name it as 'webdriver'
•    Launch this profile and perform any configurations like disabling/enabling certain add-ons, maximize, etc
•    Close the firefox browser.
•    Now, whenever this profile will be opened, it will open with the configurations that you made.



Steps to use this new profile with webdriver -

    ProfilesIni profilesIni = new ProfilesIni();

    FirefoxProfile profile = profilesIni.getProfile("webdriverprofile");

    WebDriver foxdriver = new FirefoxDriver(profile);

We might also encounter issues with security certificates on firefox, so to overcome those, the following can be used

If the certificate is valid but self-signed
    profile.setAssumeUntrustedCertificateIssuer(true); //this is the default setting

If the certificate is invalid
    profile.setAssumeUntrustedCertificateIssuer(false);


Using this code above, the webdriver will open firefox with the profile specified, and not the default one.

3.7.14

Transformation from QTP to Selenium

Proof of how bored I am right now..... :-)


Transformation from QTP to Selenium