I am using Eclipse IDE, java and Selenium Webdriver. Here is my scenario: Using an .xlsx file, I feed values to a web form. My code works fine, but if I run the scenario a 2nd time, my test fails because the values in my .xlsx file are already in use. I need a way to increment the value by 1 each time I run the test so that my application doesn't throw an error because those values are already in use. I know that I could just edit the .xlsx each time, but I want to see if there is an easier way.
Here is my code:
Utility.ExcelUtils.setExcelFile(Utility.Constant.Path_TestData + Utility.Constant.File_SellerNetwork,"Sheet1");
String sStoreNum = Utility.ExcelUtils.getCellData(1, 1);
SellerNetworkSetupPage.txt_StoreNum(driver).sendKeys(sStoreNum);
String sCustNum = Utility.ExcelUtils.getCellData(1, 2);
SellerNetworkSetupPage.txt_NewCustNum(driver).sendKeys(sCustNum);
String sNetworkName = Utility.ExcelUtils.getCellData(1, 3);
SellerNetworkSetupPage.txt_NetworkName(driver).sendKeys(sNetworkName);
SellerNetworkSetupPage.btn_Add(driver).click();
After SellerNetworkSetupPage.btn_Add(driver).click(); is performed, the application creates an account using those values. I want to be able to run this code multiple times, with different values for sStoreNum, sCustNum and sNetworkName each time.
Any help is greatly appreciated.
Just append a UID to key string values:
Something like this:
.sendKeys(sCustNum + UUID.randomUUID().toString());
If the target value is numeric, use this:
.sendKeys(sStoreNum + UUID.getLeastSignificantBits());
So each test will have its own primary key values.
Related
Is there any Intellij Idea hotkey or a plugin to quickly insert variable into string?
e.g. i have string
"My code is working, yay! Result is = ",
and i have to add construction "+variable +", resulting in
"My code is working, yay! Result is = "+ variable +"."
to properly insert a variable.
When i have to insert variables into 20+ string, its driving me nuts :)
tried to find solution on google or plugin repository, no result
PS: i know about soutv hotkey, but it cant help me since i have to change already existing strings in code
Added Live Template
Abbreviation: ++
Description: Insert variable into string
Expand with: Enter
Template text: "+ $EXPR$ +" (do not forget double quotes)
Edit Template Variable:
expression:variableOfType("") default Value: "expr"
settings screen
You type ++ in a string, press Enter, and template text is added, and you only need to choose a variable. Works like a charm.
Thanks for the idea, #Meo
I ran appScan on my application. I can see most of the Validation.Required issues for String objects. But, not sure what validation the appscan is expecting here. we have tried with null and empty check still there is no use. Please any one let me know what validation appscan expects on a string object.
String tableName = this.request.getParameter(TABLE_NAME);
session.setAttribute(tableName + "_" + parentTableName + "_editColumnMap", editableColumnsMap);
Please let me know if you need any more information
The major goal of mitigating Validatoin.required finding is to validate against malicious input. Check in your code if any variable can be set to a value that can be controlled by a malicious user. Any input taking from outside of your system should be validated or sanitized using white-listing: https://www.owasp.org/index.php/Input_Validation_Cheat_Sheet#White_List_Input_Validation
The Code is below:
RConnection connection = new RConnection();
String load_pkgs = "require(Rserve); require(forecast)";
connection.eval(load_pkgs);
String strx1 = "xData = read.table(\"D:\\\\R_TESTS\\\\ts_interval_data21.csv\",sep=\"|\",header=FALSE,col.names=c(\"a\",\"b\",\"c\",\"d\",\"xData\",\"f\"))[,\"xData\",drop=FALSE]";
connection.eval(strx1);
String strx2 = "x = xData[1:100,1]; fit = auto.arima(x);";
connection.eval(strx2);
String strx3 = "result = forecast(fit,h=12);";
connection.eval(strx3);
Object result = (Object)connection.eval("result").asNativeJavaObject();
HashMap map = (HashMap)result;
List<Object> objects = new ArrayList<Object>(map.keySet());
double values[] = (double[])objects.get(4);
for(int i=0;i<values.length;i++)
{
System.out.println((i+1)+":"+values[i]);
}
actually I'm running R inside the JAVA using Rserve() connection,now every thing works fine but when running the program the output will be totally wrong and while debugging the output is perfect. I'm not able to find the bug in my code please review the code and leave your suggestions. Thank You
I hope the following images will help:
1) Image depicts output in DEBUG mode
2) Image depicts the output in normal RUN mode
The reason behind this is the fundamental difference in Java and R storage types. As you can read in the following link: Documentation for asNativeObject() this function "tries" to convert R return-types to Java Object class. But this procedure is not successful every time. And thus I would suggest you not to use the asNativeObject() function. Try to find out a workaround using other functions.
The reason you see the difference is because the Java Object created in debug and run modes are different in their content and structure.
I am working on a Java project where I am integrating Evernote services. Right now, I am able to save, update notes, but what I would like to do is to search notes. Now, As evernote is tied to our infrastructure, I would like to save an ID of the object whose text we are copying to Evernote.
So, whenever the text is updated, I would like to get the same Note from Evernote and update it's contents.
These are the two problems I am facing :
Saving our Primary key ID in Note object. Tried it with GUID, it gets saved as I can see the note in Sandbox, but have no idea how to search notes with GUID. If GUID shouldn't be the way, then where to save the primary key which is searchable.
As mentioned in first point, which attribute or variable should be set which can be searchable.
Here is some of the saving and searching code I have so far :
Note note = new Note();
note.setTitle("New title");
String nBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
nBody += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">";
nBody += "<en-note>" + "Test" + "</en-note>";
note.setContent(nBody);
note.setGuid("1234");
Note savedNote = noteStoreClient.createNote(note);
Search code :
NoteFilter noteFilter = new NoteFilter();
// AS you can see, I have no idea what filter to set here.
// noteFilter.getTagGuids(id);
NoteList noteList = noteStoreClient.findNotes(noteFilter,0,100);
List<Note> notes = noteList.getNotes();
for(Note note : notes){
System.out.println("Note title is "+note.getTitle());
}
Kindly let me know what I can do. Thanks a lot. :-)
Udpate
This happens when I try to save the GUID with my own randomly created one.
Error log :
EDAMUserException(errorCode:BAD_DATA_FORMAT, parameter:Note.guid)
at com.evernote.edam.notestore.NoteStore$getNote_result.read(NoteStore.java:13514)
at com.evernote.edam.notestore.NoteStore$Client.recv_getNote(NoteStore.java:1346)
at com.evernote.edam.notestore.NoteStore$Client.getNote(NoteStore.java:1316)
at com.evernote.clients.NoteStoreClient.getNote(NoteStoreClient.java:368)
at com.journaldev.spring.service.EvernoteServiceImpl.findNoteById(EvernoteServiceImpl.java:157)
You can't set a manually assigned guid on a note when creating it - guids are assigned by the service and returned on the Note object as part of the createNote call on NoteStore.
As an aside, guids have a certain format, see the format here.
I want output in the following format, which we get in as400 when WRKSPLF is executed
I am using the following code for retrieving the information from as400
try
{
AS400 as400System = new AS400();
String strSpooledFileName;
SpooledFileList splfList = new SpooledFileList(as400System);
splfList.openAsynchronously();
splfList.waitForListToComplete();
Enumeration enume= splfList.getObjects();
ArrayList<SpoolVO> list = new ArrayList<SpoolVO>();
while( enume.hasMoreElements() )
{
SpoolVO splVO = new SpoolVO();
SpooledFile splf = (SpooledFile)enume.nextElement();
if (splf != null)
{
// output this spooled file's name
splVO.setFileName(splf.getStringAttribute(SpooledFile.ATTR_SPOOLFILE));
splVO.setUserName(splf.getStringAttribute(SpooledFile.ATTR_JOBUSER));
splVO.setUserData(splf.getStringAttribute(SpooledFile.ATTR_USERDATA));
splVO.setDevice(splf.getStringAttribute(SpooledFile.ATTR_OUTPUT_QUEUE));
splVO.setTotalPages(splf.getIntegerAttribute(SpooledFile.ATTR_PAGES));
splVO.setCurrentPage(splf.getIntegerAttribute(SpooledFile.ATTR_CURPAGE));
splVO.setCopy(splf.getIntegerAttribute(SpooledFile.ATTR_COPIES));
list.add(splVO);
}
}
splfList.close();
Now by using the above code I am able to get all the fields except the Options(Opt). I want Options field in java which enables me to do all the operations like send, change, hold, etc. as specified in screenshot.
Is this possible doing with java??
Thanks in advance.
Guessing that you are using JT400 you would use SpooledFileList and SpooledFile to get the details you want. Edit your question to explain the specific details you want to retrieve. Post the code you tried.
Edit:
The Options field is not an attribute of a spooled file; you can't retrieve it from anywhere. It is a field on the display panel that lets the user request an action to be performed by the WRKSPLF command. You will need to provide that functionality within your Java program. For example, if your end user types a 3, you would issue the HLDSPLF command. If she types a 6, you would issue the RLSSPLF command.