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

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;
}
}

Related

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.

How to pass multiple values using same parameter in TestNG

The website I am working on has many textboxes, after filling all the boxes I have to click on Add and repeat the same filling again on the same screen. How can I Pass the different sets of values without closing the browser using TestNG.
set 1:
Name = harry
jobid =123
occumpation = PA
Click on add button and on the same page repeat the below
Set 2:
Name = john
jobid = 125
occumpation = PA
Use TestNG data provider.
#Test(dataProvider="webSiteData")
public void myTestCase(String name, String jobId, String occupation)
{
//Your test code goes here...
}
#DataProvider(name="webSiteData")
public Object[][] getData()
{
Object [][] myData = {{"harry","123","PA"},
{"john","125","PA"}};
return myData;
}
Note: Here each row of myData represents the number of times this test method will be executed. The column represents the parameters to pass to test method. So two rows mean your test method will be executed two times with two different sets of parameters.
You can use TestNG Data provider,
Reference: http://toolsqa.com/selenium-webdriver/testng-parameters-data-provider/
OR https://www.guru99.com/parameterization-using-xml-and-dataproviders-selenium.html

How can I retrieve the contents a multi page editor plugin when selecting "Run as" in Eclipse Plugin Development?

An eclipse plugin is needed to allow users to input a script and run that script through the IDE. For this I've implemented an eclipse plugin, using the multi-page editor template. I added the extension org.eclipse.debug.ui.launchShortcuts and provided a reference to my implementation of the interface org.eclipse.debug.ui.ILaunchShortcut. This interface requires to provide an implementation of these methods:
public void launch(final ISelection selection, final String mode);
public void launch(final IEditorPart editor, final String mode);
When the user - e.g. me - right clicks the file from the project explorer, selects "run as" and selects the launcher I provided, then the implementation of this launch method is hit. The first method - i.e. the ISelection version - is hit when selecting the file from the project explorer. The second method - i.e. the IEditorPart version - is hit when right clicking the editor zone and selecting the launcher through the "run as" option from the context menu.
I now need to find out how I can retrieve the contents of that editor page. In the first method I believe I could retrieve the filename with the below code:
IFile file = (IFile) ((IStructuredSelection) selection).getFirstElement();
String path = file.getFullPath().makeAbsolute().toString();
However, the that path is relevant with respect to the root of the project. I don't know how to retrieve the path of the root of the project.
The implementation of the second method is more problematic given I don't know how to find the path based on the IEditorPart.
I hope you can help. Many thanks
If you are asking how to get the file that the editor is current editing you can use something like:
IPath filepath = null;
IEditorInput input = editor.getEditorInput();
IFile file = input.getAdapter(IFile.class);
if (file != null) {
filepath = file.getFullPath();
}
if (filepath == null) {
ILocationProvider locationProvider = input.getAdapter(ILocationProvider.class);
if (locationProvider != null) {
filepath = locationProvider.getPath(input);
}
}
which tries to get the IFile frpm the editor directly and if that fails tries for a location provider.

Print SSRSReport to file (.PDF)

I need to find a way to "print" a SrsReport, in my case SalesInvoice, as .PDF (or any kind of file) to a specific location.
For this I modified the SRSPrintDestinationSettings to output the SalesInvoice-Report as a .PDF:
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(#'\\AXDEV\Bottomline\Test\test.pdf');
Somehow this gets ignored and I recive a Email with the report as .PDF attached.
For example this will run on ax 2012 but won't print to PDF for me.
SRSPrintDestinationSettings settings;
CustInvoiceJour custInvoiceJour;
SrsReportRunController controller = new SrsReportRunController();
PurchPurchaseOrderContract rdpContract = new PurchPurchaseOrderContract();
SalesInvoiceContract salesInvoiceContract = new SalesInvoiceContract();
select firstOnly1 * from custInvoiceJour where custInvoiceJour.SalesId != "";
// Define report and report design to use
controller.parmReportName(ssrsReportStr(SalesInvoice,Report));
// Use execution mode appropriate to your situation
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
rdpContract.parmRecordId(custInvoiceJour.RecId);
controller.parmReportContract().parmRdpContract(rdpContract);
// Explicitly provide all required parameters
salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); // Record id must be passed otherwise the report will be empty
controller.parmReportContract().parmRdpContract(salesInvoiceContract);
salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); // comment this code if tested in pre release
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(#'\\AXDEV\Bottomline\Test\test.pdf');
//tokens = settings as SrsPrintDestinationTokens();
//controller.parmPrintDestinationTokens(null);
//Suppress report dialog
controller.parmShowDialog(false);
// Execute the report
controller.startOperation();
Questions:
Is this the correct way to print a srsReport to .pdf?
Am I passing/setting the printerSettings correctly?
Where does it say "Send Email"?
EDIT: Code is working fine. We are using external code of a company which simply doesnt implement this.
Use the cleaner code of Alex Kwitny
Here is working code for me. I just quickly coded this from scratch/memory based off of glancing at yours, so compare for differences.
I have two things marked (1) and (2) for you to try with your code, or just copy/paste mine.
static void JobSendToPDFInvoice(Args _args)
{
SrsReportRunController controller = new SrsReportRunController();
SRSPrintDestinationSettings settings;
CustInvoiceJour custInvoiceJour = CustInvoiceJour::findRecId(5637925275);
SalesInvoiceContract salesInvoiceContract = new SalesInvoiceContract();
Args args = new Args();
controller.parmReportName(ssrsReportStr(SalesInvoice, Report));
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
controller.parmShowDialog(false);
salesInvoiceContract.parmRecordId(custInvoiceJour.RecId);
salesInvoiceContract.parmDocumentTitle(CustInvoiceJour.InvoiceId);
salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
// (1) Try by passing args
args.record(custInvoiceJour);
args.parmEnum(PrintCopyOriginal::Original);
args.parmEnumType(enumNum(PrintCopyOriginal));
controller.parmReportContract().parmRdpContract(salesInvoiceContract);
controller.parmArgs(args);
// (2) Try explicitly preventing loading from last value
// controller.parmLoadFromSysLastValue(false);
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(#'C:\Temp\Invoice.pdf');
controller.startOperation();
}
Since you are talking about the sales invoice the report is using the print management feature and you cannot simply override the print settings like that.
You need to override the runPrintMgmt on the controller class and determine there whether you want default print management or your own code.
See this post for an example: http://www.winfosoft.com/blog/microsoft-dynamics-ax/manipulating-printer-settings-with-x

Get project in Eclipse plugin without having an open editor

In a Eclipse plugin it's easy to get the current project(IProject) if there's an editor opened, you just need to use this snippet:
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IFileEditorInput input = (IFileEditorInput)editor.getEditorInput();
IFile file = input.getFile();
IProject project = file.getProject();
But, is there a way to get the project if I don't have any kind of file opened in the editor?, i.e: imagine that you have a plugin that adds an option when you right click a project, and if you click this option a dialog window is launched, how can I print the project name in this dialog?
For menu items and the like which use a 'command' with a 'handler' you can use code in the handler which is something like:
public class CommandHandler extends AbstractHandler
{
#Override
public Object execute(ExecutionEvent event) throws ExecutionException
{
ISelection sel = HandlerUtil.getCurrentSelection(event);
if (sel instanceof IStructuredSelection)
{
Object selected = ((IStructuredSelection)sel).getFirstElement();
IResource resource = (IResource)Platform.getAdapterManager().getAdapter(selected, IResource.class);
if (resource != null)
{
IProject project = resource.getProject();
...
}
}
return null;
}
}
What do you mean by "The current project"? Getting a specific project will always require some way of uniquely identifying that specific project.
If by current project you mean that the project is open, then that's not a good criterion for uniqueness (in the general case), since multiple projects can be open at the same time.
A guarantee of uniquely defining a project is by getting a reference to a resource contained by that project. For example, this can be done through the editor input, as you state, or trough a selection, as greg pointed out.
If you have the project's name, then you can use IWorkspaceRoot#getProject(String), but I assume that's not the case. Still, for completeness:
ResourcesPlugin.getWorkspace().getRoot().getProject("MyProject");
You could also get a list of all projects, and iterate over that list to check for a property that you know the project has (or the projects have). See the example below. Of course, this again doesn't guarantee uniqueness in the general case, since there can be multiple projects that satisfy the criteria. That's why I used Lists in the example.
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
List<IProject> openProjects = new ArrayList<>();
List<IProject> myNatureProjects = new ArrayList<>();
for(IProject project : projects)
{
if(project.isOpen())
openProjects.add(project);
if(project.hasNature("MyNatureId")
myNatureProjects.add(project);
}