Showing posts with label eclipse. Show all posts
Showing posts with label eclipse. Show all posts

13.4.17

Eclipse shortcuts

If not in life, at least in eclipse, there are some shortcuts!

  • Ctrl M - maximize
  • Ctrl Shift B - breakpoint
  • Ctrl Shift / - collapse all
  • Ctrl Shift * - expand all
  • Ctrl Shift F - auto-format
    • Increase the max line width to 1000 to have all the code in a single line
    • Go to Window > Preferences > Java > Code Style > Formatter > Edit
  • String formatting
    • Go to Window > Preferences > Java > Editor > Typing
      • Escape text when pasting into string
  • Ctrl / - Toggle Line Comment
  • Alt Shift R - Rename Variable
  • Ctrl 1 - Show error resolution
  • Alt Shift Up Arrow - Select entire string
  • Ctrl Shift P - Jump to Opening/Closing Brace
  • Ctrl K - jump to the next instance
  • Alt Shift Up arrow - Select entire string in quotes
  • Go to Source/declaration - F3
  • Enable auto activation of content assist:
    • Go to Window > Preferences > Java > Editor > Content Assist > Auto activation triggers for Java
    • Add the string .abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_
    • This would have to be done individually for editors of each language


Chrome shortcuts -

  • Open chrome browser without authentication/security warnings
    • chrome –ignore-certificate-errors &> /dev/null &

12.4.17

Config to implement BDD using JBehave and Selenium

This post describes the steps to configure the complete environment and tools to be used to automate BDD tests using JBehave and Selenium
[This is a consolidated version of some earlier posts that deal with some of the topics here; refer other posts from this blog for more details]


OS / Software / Libraries / Version -
1. OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
i. Even though am having 64bit machine, all the software being used is 32-bit
2. Apache Maven 3.3.9
i. Maven home: C:\Program Files [x86]\Apache\Maven\apache-maven-3.3.9
3. Java 8 (32 bit) - 1.8.0_112
i. Java home: C:\Program Files (x86)\Java\jdk1.8.0_112
4. Selenium 3.3.1
5. Eclipse Java EE IDE Version: Neon
6. M2E Plugin [always update to latest version]
7. Log4J 1.2.17
8. Apache POI 3.15
9. OpenCSV 3.9
10. IE 11 - 32 Bit
     i. Though the parent IE process is 64 bit, but the actual instance is of 32 bit, hence, we need to run with the 32 bit driver for selenium
11. Firefox
12. Chrome

Steps -

1. Install the JDK, set the Environment variables
2. Install Maven
3. Download IDE - Eclipse
4. Download JBehave plugin

Installation and Update via the Eclipse Installer:

Help > Install New Software...
Add the new site location http://jbehave.org/reference/eclipse/updates/
Select JBehave Eclipse feature and follow standard Eclipse installation procedure
How to verify:
Go to file > new > other, and then select JBehave > New Story
If you can see the JBehave or 'New Story' then installation was succesfull.

5. Create your JBehave project -

Refer this link for more details - Create a Maven project for JBehave

  1. Create a folder - C:\Automation\BDD\
  2. Navigate to this folder via maven
  3. Run command - Use the latest version of JBehave. Update the value of this parameter -DarchetypeVersion=<latest ver>. This can be checked from Maven Central
mvn archetype:generate -DarchetypeGroupId=org.jbehave -DarchetypeArtifactId=jbehave-simple-archetype -DarchetypeVersion=4.6.3 -DarchetypeRepository=https://nexus.codehaus.org/content/repositories/releases/org/jbehave/jbehave-simple-archetype/

  • groupID: com.automation
  • artifactID:bdd
  • others as default
This would download an empty project based on jbehave-simple-archetype
  4. Go to the pom dir, then run this
mvn dependency:resolve
This could download a bunch of stuff in your local .m2 dir
  5. Go to the pom dir, and then run the command
mvn eclipse:eclipse
This could download a bunch of stuff too.


6. Import this project in eclipse -

 - Go to File > Import > Maven project
You may get a few errors when you first load the project. Try the below things to resolve.
- Go to Project > Clean
This will rebuild the project
- Use Alt+F5 with 'Force update of Snapshots/Releases' checked
This could resolve most of the errors.
Sometimes we get the following error after importing the default jbehave project in eclipse

  • ERROR Description - Plugin execution not covered by lifecycle configuration: org.jbehave:jbehave-maven-plugin:4.0.5:unpack-view-resources (execution: unpack-view-resources, phase: process-resources)
  • ERROR Resource Path - pom.xml /bddproject
  • ERROR Location - line 70
  • ERROR Type - Maven Project Build Lifecycle Mapping Problem
Resolution 1 - This is a very common error, associated with M2E plugin, and usually it goes away if we update the M2E to latest version. 
Resolution 2 - Use the QuickFix action in eclipse to mark the goal to be 'ignored'
If not use this link to figure out what needs to be done - https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html
If eclipse does not throw any errors with your new jbehave project, then your project setup is successful, but your setup is far from complete!


7. External Dependencies -

At this point you can try adding/installing other software/libraries that you need for your project, as maven dependencies. Search and copy all the dependency coordinates from the Maven Central directly, nowhere else. Add these new dependencies above the 3 jbehave dependencies already present in the pom.xml

Add dependencies for the following
  • Selenium
  • Log4J
  • Apache POI

Then the run the mvn command to resolve the dependencies
mvn dependency:resolve

Then download the required style-files for the reporting via:
mvn generate-resources
This is required only once, unless you run the clean command.

The tests can be executed via:
mvn integration-test
If this step results in BUILD SUCCESS then your basic project setup is correct and complete


Additional configuration can be done as below...

8. Configure Log4J

9. Add custom configurations for JBehave


13.5.16

Install JBehave plugins for IntelliJ and Eclipse

For IntelliJ -

Go to add plugin section, then search the repositories for 'jbehave'
The following plugins [in blue] would be needed

4.12.14

Create a BDD project via JBehave Archetype


The fastest way to start building and automating BDD Stories via JBehave tool is to have the entire Framework/Project structure created via Maven Archetypes using the jbehave-simple-archetype.

This generates a project structure with all the necessary config and guidelines which help in implementing the Story files right away, and saves us a lot of time in writing a lot of boiler-plate-code.

Just navigate to the dir [lets say, C:\BDD\] where you want to keep all your BDD projects, and then enter the below in the cmd prompt to download the project via mvn

mvn archetype:generate -DarchetypeGroupId=org.jbehave -DarchetypeArtifactId=jbehave-simple-archetype -DarchetypeVersion=4.6.3 -DarchetypeRepository=https://nexus.codehaus.org/content/repositories/releases/org/jbehave/jbehave-simple-archetype/


Project Specification - 
  • When asked to enter a groupID, enter like: com.company.department
  • When asked to enter an atifactID, enter like: bdd-jbehave
  • When you are asked to define value for version just press enter to select the default version as 1.0-SNAPSHOT
  • Let the default package be same as groupId so press Enter and confirm the details by typing “y” and then enter as seen below.
  • After successful completion you will see a folder named after your artifactId in your workspace which contains a pom.xml and also src folder.
  • This would also contain a sample MyStories.java and MySteps.java files, with default config

We get the following major classes/files
  • MyStories.java - contains all config to run JBehave stories
  • MySteps.java - contains implementation of all steps
  • my.story - contains all the scenarios for a story
  • pom.xml with all the dependencies and build config





That's it, your maven project is created. You can use this as a template to add your own story, steps and other classes.


To open the project in IntelliJ - 
Select the option to import a new project from the IDE, and then specify the pom.xml for the newly created jbehave project.
On the subsequent windows, select the option to automatically download the Source and Documentation. This will automatically download all the packages that you import in your classes, as and when they are used, and will prevent package not found errors.
Ensure that the JBehave plugin is installed in IntelliJ, before importing the project.
Ensure that you select the 'Sources' and 'Documentation' checkboxes while importing, so that all the dependencies get downloaded.



[Optional step] To open the project in Eclipse - 
Now cd into the folder jbehave which contains the pom.xml and then execute the following command:
    mvn eclipse:eclipse
This command will make your project an eclipse project which can be opened through eclipse by adding the relevant .classpath and .project files.

That's it, you are ready to do BDD, just behave!

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.