Feature file 'scenario outline' data array item not being picked by in Step Definition - intellisense

I set up a Feature File with a scenario outline, but then I can not use the data array item in my step definition file.
i.e. 'address' is my feature file data array item,
but in my step definition file, 'address' is underlined by Eclipse IntelliSense as an error and this gives an 'Arity mismatch' message if run.
I am new to automation and want my step definition to pick up the Feature File scenario outline array data.
Can anybody spot what I am doing wrong?
Feature: Login
Scenario Outline: Successful login
Given HomePage '<address>'
When ValidCredentials
Then LoginSuccessfull
Examples:
|address|
|https://totaljobs.com|
//Step Definition extract
#Given("HomePage '(.*?)'")
public void HomePage() {
driver.get(address);
driver.manage().window().setSize(new Dimension(1536, 792));
System.out.println("Chrome opened");
String url = driver.getCurrentUrl();
System.out.println("Current url:" +url);
}

Related

Selenium Webdriver not reading CSV file using CSVReader

I am executing a script for a Salesforce page flow with Chrome Webdriver. The flows are written in Selenium JUnit code, exported and executed as JAR (JUnit Request Sampler) in JMeter 5.4.1. The page has a pop-up which has a textbox. which should read all values from a CSV file (currently kept within Selenium Project) one by one [eg. value1, value2...value n] (1 column,'n' rows) until all values are finished. Once one data is entered, "Next" button is clicked for next value to be captured from CSV. "Tube1Id" is the element name of the textbox.
Currently the flow when run in JMeter executes till Textbox display in pop-up and stops, just on the step to read the CSV file. Can anyone please help?
public void jmeterTest() throws InterruptedException
{
try
{
String CSVPath = "C:\\Users\\user\\Documents\\CAREDx\\SeleniumProject\\SeleniumProject\\CSVSamples\\samples.csv";
driver.get("https://baseurl/");
/* code for pop up window open with Textbox*/
WebElement Tube1Id = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[#name='Tube1Id']")));
CSVReader reader = null;
reader = new CSVReader(new FileReader(CSVPath));
String[] samples;
while ((samples = reader.readNext()) != null)
{
String TubeId = samples[0];
Tube1Id.sendKeys(TubeId);
log.info(threadName + ":: Tube ID :: " + TubeId);
/* code for Next button click */
}
}
}
I found another way to work this out since reading data from an external csv file location didn't work.
I added a CSV Dataset config element in JMeter under JUnit Request [Thread Group>JUnit Request>CSV Data set config], added csv location and variable name (samples). I added the values in CSV file as value 1#value 2#...#value n. In the selenium code I added :
String samples = junitSampler.getThreadContext().getVariables().get("samples");
String[] arrOfStr = samples.split("#");
/* in-between code */
for (String TubeID : arrOfStr)
{
Tube1Id.clear();
Tube1Id.sendKeys(TubeID);
/* remaining code for click Next */
}
It's working.

is there a way to pass data directly in Step definition without passing in feature file?

i want to use dataprovider to pass data directly into step definition without passing from feature file, as i want to pass null values as well. here is what i am doing.
Scenario: User should get empty field highlight, when that fields is empty and clicked submit. When Submit is clicked after providing values in nethier or either of Reg Id or PC
#Test(dataProvider = "getData")
#When("^Submit is clicked after providing values in nethier or either of Reg Id or PC$")
public void submit_is_clicked_after_providing_values_in_nethier_or_either_of_reg_id_something_or_pc_something(
String regvalue, String pcvalue) throws Throwable {
//code
}
#DataProvider
public Object[][] getData() {
Object[][] data = new Object[3][2]; // 3 is number of combinations and 2 is number of values
// 1st set
data[0][0] = "Username1";
data[0][1] = null;
// 2nd set
data[1][0] = null;
data[1][1] = "Password1";
// 3nd set
data[2][0] = null;
data[2][1] = null;
return data;
}
Error i am getting is
Step [^Submit is clicked after providing values in nethier or either of Reg Id or PC$] is defined with 2 parameters at 'com.commcard.stepdefinition.StepDef.submit_is_clicked_after_providing_values_in_nethier_or_either_of_reg_id_something_or_pc_something(String,String) in file:/D:/Eclipse-Workspace/CucumberProject.CitiCommCard/target/test-classes/'.
However, the gherkin step has 0 arguments.
You can use a yml file as a data-lookup. For JSON style testing I would advocate this. As you can use a regular fixture or build it up mid-process.
So you could have something like this.
Given I have a valid request to create a user
But the username is invalid
Given I have a valid request to create a user
But the username is too short
# yaml file
user:
create:
issues:
username:
invalid: "Can't Use W3!rd char$"
too_short: "usrnm"
Then your steps just use whatever programming language you use and convert the yml into a data lookup (Hash/List), and alter the keys.

Cucumber "Doc Strings" in Serenity Reports

We are thinking to make some tests in Cucumber in the way of getting Living Documentation, and the key for the "Living documentation" is that in the "Then" we want to use "Doc Strings" (Json strings).
But, we realized that the "Doc Strings" are not shown in the Serenity Reports.
Is there any possibility to show the "Doc Strings" inside the Serenity Reports?
Thank you!
It is actually possible. I've created an example Git project that shows how to add custom messages to the Serenity test report using the StepEventBus API of Serenity BDD.
The complete code with further explanations is available at: https://github.com/datentyp/stackoverflow.com-questions-47492400-cucumber-doc-strings-in-serenity-reports
public class TestSteps implements En {
public TestSteps() {
Given("some scenario", () -> { /* implement me! */});
When("some step contains some doc string", () -> { /* implement me! */});
/* implement me */
Then("the content of that doc string should be included in the Serenity test report", this::showStepMessage);
}
public void showStepMessage(String message) {
// TODO: escape message string for use in HTML
String escapedMessage = StringUtils.replace(message, " ", " ");
StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle(escapedMessage));
StepEventBus.getEventBus().stepFinished();
}
}
But note that if you really want to append some JSON Doc Strings to your Then steps than I think you might be trying to do the wrong thing in the first place.
You can capture the actual HTTP request/response that was send over the wire by using serenity-rest-assured. This way your reports will not only include the expected JSON payload but also the HTTP headers and payload of both, the request and the response.
If you are interested in this have a look at the documentation: http://thucydides.info/docs/serenity-staging/#_testing_rest_with_serenity_bdd

How to Capture data, store data, perform math operations and verify data in IBM Mobilefirst TestWorkbench 8.6.0.1

Tool: IBM Mobilefirst TestWorkbench 8.6.0.1
OS: Windows 7
Have an app which displays 3 text boxes, two to input numbers and a third displays the sum of numbers
Record a test. (Enter number in each of the two text box; the result is displayed in the third test box)
While playback, is it possible to store the numbers in variables, add them and cross-verify with result that the app displays ?
The above would help us to verify transactions in banking applications
yes, it is possible
First, create a variable in your script (open 'Text Resources' node, right
click on 'Test Variables' and choose 'Add' menu
Then, in the mobile data view, right-click on the element that
contain the number, and choose 'Create a variable assignment from Text' and assign the value to the variable you have just created before
Do the same for the second variable
Then at the point of the script where you want to do the sum, just add a custom code splitting first the script (menu 'Split Mobile or Web UI actions..') and insert a custom code (menu 'Insert > Custom Code' on the 'In application' node that you have just created)
Add the 2 variables as parameters of the custom code and implement the sum
You can find custom code examples here http://www-01.ibm.com/support/knowledgecenter/SSBLQQ_8.7.0/com.ibm.rational.test.lt.common.doc/topics/textndteswcc.html?cp=SSBLQQ_8.7.0%2F0-6-11-0&lang=en
Dominique
Find below Custon Code i have used for doing the operation i mentioned in the question(Edited a bit)
In "Custom Code Details" Add arguments. args[0] in code refers to the first argument added in "Custom Code Details".
package customcode;
import org.eclipse.hyades.test.common.event.VerdictEvent;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
/**
* #author unknown
*/
public class Class implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
/**
* Instances of this will be created using the no-arg constructor.
*/
public Class() {
}
/**
* For javadoc of ICustomCode2 and ITestExecutionServices interfaces, select 'Help Contents' in the
* Help menu and select 'Extending Rational Performance Tester functionality' -> 'Extending test execution with custom code'
*/
public String exec(ITestExecutionServices tes, String[] args) {
String L4_InitBalance = args[1];
String L1_InitBalance = args[0];
String L4_FinalBalance = args[3];
String L1_FinalBalance = args[2];
if((L4_InitBalance == L4_FinalBalanc)&&(L1_InitBalance == L1_FinalBalance))
tes.getTestLogManager().reportVerificationPoint("SFT PASSED",VerdictEvent.VERDICT_PASS,"SFT has PASSED");
else
tes.getTestLogManager().reportVerificationPoint("SFT FAILED",VerdictEvent.VERDICT_FAIL,"SFT has FAILED");
return null;
}
}

How to use "isTrue" method of "Text" class?

I am unable to use "isTrue" method of text class
Here is the "Text" class detail
http://selenium.googlecode.com/git/docs/api/java/index.html
// Code i have written
public void researchSelenium(){
driver.get(baseUrl);
ConditionRunner.Context cont = new Research();
Text obj = new Text("Why implement a customer referral program?");
System.out.println(obj.isTrue(cont));
driver.close();
driver.quit();
I dont know what to do here
ConditionRunner.Context cont = new Research(); //After "new" what should i write?
object of ConditionRunner.Context will pass to "isTrue" method
I'm going to make a few presumptions here:
driver is a selenium web driver instance
You are trying to find if a text field is present in your web page
You know what the text is, but not its xpath (or at least do not care "where" it is).
In this case, you just have a minor syntaxical error
public void researchSelenium()
{
driver.get(baseUrl);
//Not sure what this is doing.
ConditionRunner.Context cont = new Research();
//Small chgange here
string obj = "Why implement a customer referral program?";
System.out.println(driver.isTextPresent(obj));
driver.close();
driver.quit();
}
NB. the above is "free coded" and I've not tested/complied it. Feel free to edit if there's a minor problem.
APPEND:
Personally I'd use NUnit to handle tests, so in that case I'd use:
Assert.isTrue(driver.isTextPresent(obj));
To test if that text was actually present, but how you're running your tests is not something that's stated in your question.