What files I should use in Automation testing framework - selenium

I am making Automation Framework using Selenium , JAVA, Maven, TestNG & Eclipse.
So my question is regarding which TYPE OF FILE I should use for:
Keeping test Data ? (Right now I am using XML file as it is light &
free unlike Excel)
Creating test case. ? (Currently I am using simple .Java text file for each test case)
For creating Reports ? (Thinking to make XML report & then display it using HTML file)
Will be nice if you share Pros & Cons along with your views/recommendation/suggestion.
I think this will help me finalize my file structure. We can add functionality & facilities anytime.
Thanks a lot.

Keeping test Data, you might want to try using .Java files to store data, then use getter and setter. If you are using TestNG you can use the annotation #DataProvider() which will really help you on keeping test data.
Constants can also be put in . Java files as an interface
Creating test case --> It is a good thing to use .Java file
Creating reports --> Yep, you got the idea. Try to use TestNG, it's easy to set up.

Related

Cucumber Gherkin: Is there a way to have your gherkin features written and managed in excel sheets instead of .feature files in IntelliJ or eclipse?

Cucumber Gherkin: Is there a way to have your gherkin scenarios written and managed in excel sheets instead of .feature files in IntelliJ or Eclipse like in SpecFlow+Excel(screenshot given as link below)? I am using Cucumber-JVM with selenium for my automation framework.
Excel based Scenarios
PS: Will there be any pros or cons to using excel sheets as your feature files?
No, Gherkin is the language understood by Cucumber.
If you want to introduce Excel in the equation, you probably want to use some other tool. Or implement your own functionality that reads Excel and does something interesting based on the content.
You could write a compiler that takes .csv files and translates them into feature files by doing a write.
Here's a quick thing I whipped up in JS that does just that.
First it removes blank lines, then searches through for keywords with a missing colon (it might happen somewhere down the road) and adds those in, checks for an examples table, and as per your photo, this was easy to do, as it was just checking whether the start character was a comma (after having removed the blank lines, and keywords always being in the first section). Finally, removing the rest of the commas.
The only difference, I believe, is that mine included the Feature: and Scenario:/Scenario Outline line that is needed to create a valid scenario in cucumber.
So yes. It is possible. You'll just have to compile the csv's into feature files first.
function constructFeature(csvData) {
let data = csvData,
blankLineRegex = /^,+$/gm,
keywordsWithCommasRegex = /(Feature|Scenario|Scenario Outline|Ability|Business Need|Examples|Background),/gm,
examplesTableRegex = /^,.*$/gm;
data = data
.toString()
.replace(blankLineRegex, "");
data.match(keywordsWithCommasRegex).forEach((match) => {
data = data.replace(match, match.replace(',', ":,"))
});
data.match(examplesTableRegex).forEach((match) => {
data = data.replace(match, match.replace(/,/g, "|").replace(/$/, "|"))
});
data = data.replace(/,/g, " ");
data = data.replace(/\ +/g, " ");
console.log(data);
}
let featureToBuild = `Feature,I should be able to eat apples,,
,,,
Scenario Outline,I eat my apples,,
Given,I have ,<start>,apples
When,I eat,<eat>,apples
Then,I should have,<end>,apples
,,,
Examples,,,
,start,eat,end
,4,2,2
,3,2,1
,4,3,1`
constructFeature(featureToBuild);
Just take that output and shove it into an aptly named feature file.
And here's the original excel document:
The downside of using Excel is that you'll be using Excel.
The upside of using feature files as part of your project are:
* they are under version control (assuming you use git or similar)
* you IDE with Cucumber plugin can help you:
- For instance, IntelliJ (which has a free Community edition) will highlight any steps that have not been implemented yet, or suggest steps that have been implemented
- You can also generate step definitions from your feature file
* when running tests you will see if and where your feature file violates Gherkin syntax
TL;DR: Having the feature file with your code base will make it easier to write and implement scenarios!
Also, like #Thomas Sundberg said, Cucumber cannot read Excel.
Cucumber can only process the feature files, so you will have to copy your scenarios from Excel to feature files at some point.
So what you are asking is not possible with Cucumber.
If you want to read test cases from Excel you'll have to build your own data driven tests. You could for instance use Apache POI.
There's a solution out there which does scenarios and data only in Excel. However, this I have tried in conjunction with Cucumber and not with any test application. You could try and see if you want to use this:
Acceptance Tests Excel Addin (for Gherkin)
However, not that Excel as a workbook or multiple workbooks can be source controlled, but it is hard to maintain revisions.
But then Excel provides you flexibility with managing data. You must also think not duplicating your test information and data in multiple places. So check this out, may be helpful.

Folder specific cucumber-reporting without parallel run?

Was wondering if I could get setup cucumber-reporting for specific folders?
For example in the https://github.com/intuit/karate#naming-conventions, in CatsRunner.java i set up the third party cucumber reporting? without parallel execution. please advise or direct me on how to set it up.
Rationale. its easier to read and helps me in debugging
You are always recommended to use the 3rd party Cucumber Reporting when you want HTML reports. And you can create as many Java classes similar to the DemoTestParallel in different packages. The first argument to CucumberRunner.parallel() needs to be a Java class - and by default, the same package and sub-folders will be scanned for *.feature files.
BUT I think your question is simply how to easily debug a single feature in dev-mode. Easy, just use the #RunWith(Karate.class) JUnit runner: video | documentation

I want to create bat file, The Selenium Project is been developed using TESTNG and Java. I have suite in xml.

Now i want to create bat file, Please file in creating bat file.
I don't have main function in my project.
I want to run the test suite in Main class. How can i do that ? Source code please.
You can generate your xml from main function.
I can provide source code, but it is against policy of stackOverflow.
first show your research.
I think many might have answered this.
Hint: use TestNG class
and add XMLTest, XMLSuite and XMLClass objects to it.

Create Fitnesse pages without using Camel-Case

I am currently migrating a huge amount of scripts to Fitnesse. I implemented a converter that takes the existing scripts XML and converts them to Fitnesse Files (e.g. content.txt). This is working correctly. However, I am still facing a problem with the names since they are not camel-case formatted (an example of a script name is the following: BANK_Tran_BankStmtLoad_Add). Most of the scripts have such names. It is possible to programatically remove the "_" but this won't work as well since we still have several consecutive capital letters. Is there a way to create new pages in Fitnesse without having to write the names in Camel-case.
Thanks in advance.
Looks like this is baked into FitNesse. I tried manually creating the FitNesse folders but no luck. You can run tests outside FitNesse with Folder Runner: http://fitsharp.github.com/Fit/FolderRunner.html or http://fitnesse.org/FitNesse.UserGuide.FitLibraryUserGuide.FolderRunner

Java program for code-formatting

Is there a program (Java program) to format code according to Java code format conventions?
Does an Ant task exist?
There is an Ant external task for Jalopy.
http://ant.apache.org/external.html
http://jalopy.sourceforge.net/
http://ant.apache.org/faq.html#adding-external-tasks
Hope this helps
Eclipse will automatically do this for you if you tell it to. or at least it will do an awful lot of it. I doubt it would rename variables to meet the coding standard though.
Click on the properties for you project and look at the options under "Java Code Style"
You will have to open each file individually and save it though.
You can also install CheckStyle to enforce coding standards.