Most Viewed Pages

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!

Steps to install and configure Maven

Steps to install Maven

Prerequisite - Ensure that Java is installed, and the environment variable 'JAVA_HOME' is set as follows:
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_10

Download and unzip the maven binary file into a location like 'C:\Program Files\Apache\maven'. There is no exe to run.

Set the environment variables. Open the cmd prompt and type in the below commands as is

set M2_HOME=C:\Custom_Install_Dir\Apache\maven
set MAVEN_HOME=C:\Custom_Install_Dir\Apache\maven

Then append this to the Path variable as below, so that we can run the maven commands from anywhere
set Path=C:\Apache\maven\apache-maven-3.6.1\bin;

You can also do this by directly editing the Environment Variables, if you have admin rights.

How to check if maven has been installed correctly?

If we get an output like below to the command 'mvn -version', then we are all set

That's it, maven is installed and configured!



Some DONTs -
  • No need to set up MAVEN_OPTS Env param anymore.
    • All the options can now be set via the JVM Config file - to be added as - ${maven.projectBasedir}/.mvn/jvm.config 
    • This file will become part of your project and will be checked in along with your project.
    • Also this is way easier than having to get admin rights in enterprise setups.
  • Dont place your maven in a dir having spaces in its path.

Common Troubleshooting -
  •  If you are still having issues, even after following the above steps correctly, first restart the machine before doing any more troubleshooting
  • If 'mvn' command does not work directly, give the entire path till the bin dir of maven, and then try - if this works, then it means maven is installed and recognized, but it cannot run from everywhere. So all you need to fix are the Environment Variables.
  • By default Eclipse points to its own Embedded version of Maven and this could be different from the one that you installed, so we should update Eclipse to use the same Maven package and version via Eclipse > Preferences
  • Ensure that the Path variable has both these values - C:\Program Files\Java\jdk1.8.0_211\bin;C:\Apache\maven\apache-maven-3.6.1\bin;

2.12.14

Function to delete firefox cookies with VbScript / QTP

There is a QTP Util method to delete browser cookies, but that works only for IE.
Deleting the cookies for firefox programatically is a little tricky, specially if there are multiple profiles that you are using, but here is a function to do just that.

Function funcDeleteCookies()

''Ignoring any errors that may arise during file deletion

On Error Resume Next

''This function will work best when firefox is closed

Call funcTerminateProcess("firefox.exe")

''Defining the list of files that need to be deleted to clear the cache

'' arrFileToDel = Array("compatibility.ini","cookies.sqlite","cookies.sqlite-shm","cookies.sqlite-wal","extensions.ini","extensions.sqlite","formhistory.sqlite","key3.db","localstore.rdf","permissions.sqlite","places.sqlite","places.sqlite-shm","places.sqlite-wal","prefs.js","sessionstore.bak","sessionstore.js","urlclassifierkey3.txt","webappsstore.sqlite")

arrFileToDel = Array("cookies.sqlite","cookies.sqlite-shm","cookies.sqlite-wal","formhistory.sqlite","places.sqlite","places.sqlite-shm","places.sqlite-wal","sessionstore.bak","sessionstore.js","localstore.rdf","formhistory.sqlite","key3.db")


''Getting the current logged in user, because the path is user specific

sUserName = Environment("UserName")

''Location of the firefox profile folder

sProfileFolderFox = "C:\Users\" & sUserName & "\AppData\Roaming\Mozilla\Firefox\Profiles"

Set oFolderFSO = CreateObject("Scripting.FileSystemObject")


If Not oFolderFSO.FolderExists(sProfileFolderFox) Then


Call funcLogger(micWarning, "The firefox cache folder could not be located", "Cache not cleared. " & sProfileFolderFox)


Else


''Getting all the sub folders

Set oChildFolders = oFolderFSO.GetFolder(sProfileFolderFox).SubFolders

''Looping for each of the sub folders

For Each oFolder In oChildFolders

sCurrFolderName = oFolder.Name


''Generally its enough to clear the cache from the default folder, which is what we are checking below

If InStr(1,LCase(sCurrFolderName),".default",1) Then

''Deleting the files

For i = 0 To UBound(arrFileToDel) - 1
oFolderFSO.DeleteFile(sProfileFolderFox & "\" & sCurrFolderName & "\" & arrFileToDel(i))
Next

End If


Next


End If


''Enabling errors again

On Error GoTo 0

End Function