Xpages only passes first character to Agent - xpages

I have created an Xpage to allow the administrator to input a single Notes Document (They are Contracts) ID into an edit box and press a button to delete the Contract. The delete calls an Agent passing the Contract ID. Below is the button script and then the relevant part of the Agent. What is happening is only the first character is being passed to the Agent, i.e if the Contract ID is 9MXCB4 only "9" is being passed as the Agent message box prints this to the log. What am I doing wrong here? If I hard code a Contract ID after the message box the Contract is processed correctly.
Button code
ag = database.getAgent("DeleteOneContract");
noteid = getComponent("ContractIDDelete").getValue()
ag.run(noteid)
Part of Agent code
Dim runAgent As NotesAgent
Dim deleteID As Variant
deleteID = runAgent.Parameterdocid
MsgBox "Input is " & deleteID
'If line below is uncommented it processes the Contract correctly
'deleteID = "9MXCB4"
' Rest of agent process
....
Note that I have also tried runAgent.Target and runAgent.Query

Just tested that and when I pass it a valid NoteID, the agent reads it just fine. I don't think you can pass any other value than a NoteID to the agent this way.
An alternative might be to use the agent.runWithDocumentContext(doc) method and retrieve the document before sending it to the agent.

I believe that the note ID parameter has to actually be a hexidecimal number in string form. It doesn't have to line up with an actual note ID in the database, but it can only contain 0-9 and A-F (with presumably a cap on size).

To add an extra thought on Jesse's and Mark's correct answers: from AJF's question we cannot tell whether the Xpage is bound to an actual NotesDocument object, or whether it is a (temporary) stand-alone page. In that case, of course, agent.runWithDocumentContext won't work.
But unless you have a good reason to perform the rest of your task using a LotusScript coding: why use an agent in the first place? Why not perform the deletion directly using SSJS code? On the Xpages side of the process you most probably will have to start with SSJS code very similar to Mark's example, but then why not go ahead and finish it off with two or three more lines?
In fact I try to avoid calling agents directly from my Xpages driven applications, due to performance issues, and because I don't like my code to be scattered all over the place.

Related

basic blue prism email login object

Trying to learn basic blue prism.
I have made an object to login to my gmail account.
It enters the page where mail id has to be entered. The email id gets entered and the next page appears where the password has to be entered. But in the writer tool it shows the following message : "Internal : Failed to perform step 1 in Write Stage 'Writer2' on page 'Initialise' - No elements match the supplied query terms"
I looked into all the most obvious bugs and I cant find anything wrong. Can someone please give any suggestions as to what the problem could be?
The specific error message you're getting indicates there's an issue with your spying of the element you're attempting a Write on.
Without knowing anything else about the way you've included/excluded certain attributes of the element you're attempting to write to, the only sound advice one could offer would be to open the Application Modeler and trial-and-error the "Match?" for each attribute until you're able to use the "Highlight" button and verify a single interface element is selected. (Usually in circumstances such as yours, the "Value" attribute of the element you've spied has its Match checkbox selected, but the value has changed since spying it, thus making it not a match.)
check if the data item you are storing the password in is of password type.
You can reset the password by going ahead with the "write" property and delete once and drag-drop again at the same place and click OK. reset the flowchart and run them again, you'll not get the error. I had faced the same issue earlier and got fixed.
It sometimes happens due to the slowness of your internet connection BP not able to read the data item info and directly moved to next steps, to fix it, you can use wait functionality and give the 8-10 sec of wait time.
Hope this helps.
stay blessed!
When spying a browser please make sure you are using HTML mode to capture the necessary Element (please note that BP only supports IE, so no Chrome or other browser!). Also, please remember that the browser page you are spying has to be launched from the Application Modeller in order to be "attached" by BP.
To cycle between modes, simply hit the Alt key after clicking "Identify" on the Application Modeller. After you have captured the correct area of the page where your password goes, uncheck all the attributes of the element that are blank and also the URL attribute (you should be left with 4 maybe 5 atributes left), then hit "Apply" and "OK". Click "Highlight" to make sure BP still finds the element of the page that you want. Then in your Process or Object canvas, use a "Write" stage and drop this element you just created in the Element field, and the password into the Value field (the value has to be between "" unless you are using a data item instead of typing it in). If you have done all this, the "Write" stage should most definitely enter the password into the password field. Good luck!

How to implement 'if' in Gherkin

I am trying to convert Selenium test to Gherkin. Is there way to implement if statements in Gherkin?
Example : assume the code is written in the below format. I am just writing description as below. Please understand the part after double slash is the actual Selenium code:
// launch the application
// login to application
// navigate to page
String str;
if(str== "XYZ")
{
// verify title
}
//verify text field 1
//verify test field 2
//verify select box
For this I am trying to write code in Gherkin as follows
Given user launches the application
When user login with valid credentials
and navigate to required page
When String str is "XYZ"
Then verify title
And verify text field 1
And verify test field 2
And verify select box
but this code is incorrect because if the str is not equal to "XYZ" we want that title should not be verified but other verification like text field1,2 and select box should be verified.
You don't implement if in Gherkin.
Gherkin is about communication and those you want to communicate with, non coders, don't know what an if statement is. They don't care either.
The solution? Two scenarios to cover both cases.
Ideally, this level of detail would not be in your Gherkin scenario. The best approach is describe business use cases, not low level details. This is what Gherkin is designed for: communicating with non-technical stakeholders so that you can work out if you are building the right thing in the first place. Here is what I would write:
Given the user is logged in
And the user is on the required page
When they enter data that requires the optional fields to be validated
And they enter invalid data in the optional fields
Then the form shows an error on the optional fields
The low level details don't matter (that the string is specifically "XYZ" or that it is the title field is not important), so these should be hidden in the step definition and/or unit tests.
In order to continue to check the other fields, you can just add another step after this:
When they enter invalid data in all of the other fields
Then each other field has an error message attached to it.
Again, there is no need to specify the actual fields, or separate them into their own steps. The idea is to express the high level business value of the scenario, i.e. that the form is validated when it should be.
The advantage to keeping things high level is that when the form changes (as it eventually probably will), then this scenario can remain untouched. Which is correct as the business case is the same: it should validate when it's supposed to. All the changes will be in the step definitions. This means that there is no reason to have another discussion with your stakeholders about whether your scenarios are still testing the right thing.
You can write the scenario, somewhat like this:
Given the user launches the application
When user login with valid credentials
And navigates to required page
Then he should see the page datails
Inside the Then step you manage all the logic.
Then(/^he should see the page details$/) do
if condition
...
else
...
end
end
Gherkin is not a programming language to use if or else conditions. It is a part of BDD framework, that is implemented, to make the stakeholders and other non technical resources understand what the test process is about. Hence, it is always recommended, you keep the gherkin as simple and as generic as possible.
Strictly speaking you should create an alternative statement along the lines of:
Given user launches the application
When user login with valid credentials
and navigate to required page
When String str is NOT "XYZ"

Difference in doc created by agent vs gui QuerySave fails to allow ODBC transfer

After I create a doc in a Notes app, I'm moving information from that doc to a postgres db.
The agent that transfers the data to postgres uses a field in the doc as the key field.
I'm running into the following problem:
- If I create the doc via the Notes client, the transfer occurs without problems.
- If I create the doc from an agent (which processes an incoming email and generates a valid key field value), the transfer fails with a null key error. If I then open and save the doc, the transfer is successful.
I key field value is not null, however. I can see it in the view, in the document, and in the document properties.
Any thoughts on how I might be able to figure this out would be appreciated.
thanks!
clem
============================
Thanks Torsten for the reply. I appreciate it. Well, there's not much to the code, really. Here's part of it. "x.LogNumber" returns a string. The format is something like T1234CP. I ended up adding the computeWithForm and setting the IsSummary tho I don't think it was necessary.
atdoc.logNumber = x.LogNumber
Call atdoc.computeWithForm(false, false)
Dim lnItem As NotesItem
Set lnItem = atDoc.getfirstitem("logNumber")
lnItem.IsSummary=True
Call atdoc.save(True, False)
=======================================
Once the doc is created, an agent runs that transfers some data from the doc to the postgres db via odbc:
'.. define the 'key field' to be use in the connection.select call
Dim selectFldLst As New LCFieldList
'.. add the key field name to the LCfieldList object.
Call selectFldLst.Append(NotesKeyFieldName, LCTYPE_TEXT)
'.. set this field to be the key field.
selectFldLst.Getfield(1).flags = LCFIELDF_KEY
Set Notes_LCFieldList = New LCFieldList ' flSrc
Set odbcDB_LCfieldList = New LCFieldList ' flDest
'.. get the key of the doc to transfer.
Set docWithTransferID = docsToTransferViewEntry.Document
selectFldLst.LogNumber = Trim(docWithTransferID.stid(0))
count = Notes_LCConnection.Select(selectFldLst, 1, Notes_LCFieldList)
^--- This selects the fields from the Notes document. This is where it fails. It returns 0 for 'count'. It should return 1. If I save the document manually, it works.
Sounds like your form is doing something to it. As a quick and dirty fix you could try doc.computeWithForm() in your agent before saving.
You create the records from Notes? Save yourself the trouble with code in the events and configure DECS. It creates the document for you reliably.
Most probably the items in the document you create do not have the "Summary" property set. That makes them "invisible" for some functions / subs...
Please provide some code about how you create the items. If you do it like Set item = New Item(doc, "Name", "Value") then the item will not be summary. Then you need to call a item.issummary = true
Taking into account the last comments I guess, that the agent sets the item with the wrong datatype. Again: The code of the agent would have helped to identify this.
If for example the Field in the document is of type text and the agent writes something like
docWithTransferID.stid = 1 then everything "seems" to be OK, as the field is shown correctly in the views and in the Form. But in the Properties of the document it will be shown as number. As soon as you save the document, the design of the form will force it to be a Text.
The same thing works vice versa. If the agent reads the data from a textfile (e.g) and does something like docWithTransferID.stid = "1", then the item will be text, no matter how it is defined in the Form. As soon as you save the document -> Voila, it will be a number again.
Background LotusScript does not know ANYTHING about the Form and therefor does not obey datatypes or formats... You have to take care for this yourself.

Restricting access in Lotus Notes form

I would like to be able to let all users to create a form (QCR) but then no one should be able to edit the form except me and one other user. I have been tinkering around with the ACL and Authors and Readers field but have no luck.
Some more background:
1. This form is created by clicking a button from a separate database because some of the information in this QCR form are inherited from that database.
2. Users in the All group should be able to create this form
3. The users should be able to read all the documents in the QCR database but not edit them
4. I and one other users should be able to to read and edit all the documents
5. There are some codes in the QuerySave event to compare the value before and after a documents is being edited
What I have tried:
I created a group QCR_Access that has me and 1 other user as members. Then I created an Authors field, computed, with 'QCR_Access' as the Formula in the QCR Form. But no matter what kind of Access type that I gave to the All group (Depositor or Author), the application keeps giving me error whenever I tried to save a new document in the database with one of the user in the ALL group.
Below is the codes in the Querysave, might help give you some idea what I am doing.
Sub Querysave(Source As Notesuidocument, Continue As Variant)
' Compare the values in the form after it is saved with its original values when the document is not a new document.
Dim doc As NotesDocument
Set doc = Source.Document
Dim session As New NotesSession
Dim user As String
user = session.CommonUserName
If newDoc Then
doc.Log_Date = Cstr(Now())
doc.Log_User = user
doc.Log_Actions = "New document created."
Else
' Load fields value to the array
lastValues(0) = doc.QCR_Requestor(0)
lastValues(1) = doc.QCR_No(0)
...
lastValues(31) = doc.QCR_Tracking_Info(0)
' Compared each value in the array to see if there is any difference
Dim i As Integer
For i = 0 To 31
If lastValues(i) <> originalValues(i) Then
Call UpdateLogFields(doc,user,i)
End If
Next
End If
End Sub
Sub UpdateLogFields (doc As NotesDocument, user As String, i As Integer)
Dim logDate As NotesItem
Dim logUser As NotesItem
Dim logActions As NotesItem
Set logDate = doc.GetFirstItem("Log_Date")
Set logUser = doc.GetFirstItem("Log_User")
Set logActions = doc.GetFirstItem("Log_Actions")
' a space is needed otherwise the appended text is right next to the border
Call logDate.AppendToTextList(" " & Cstr(Now()))
Call logUser.AppendToTextList(" " & user)
Select Case i
Case 0: Call logActions.AppendToTextList(" Requestor is changed.")
Case 1: Call logActions.AppendToTextList(" QCR No is changed.")
...
Case 30: Call logActions.AppendToTextList(" Follow Up information is changed.")
Case 31: Call logActions.AppendToTextList(" Tracking information is changed.")
End Select
End Sub
I think you must definitely use authors field here, your description fits exactly for purpose... I would recommend you to use a role in this case thought, because that way you can assign it to someone else in emergencies or if you leave the company...
If you ACL is correctly setup, the you only need to add the value of the role like this in your authors field "[role]" I have attached a link with an image that shows how should your field look like if you inspect it.
http://bp1.blogger.com/T-j3ZLqfNQ/RsQXnWk20uI/AAAAAAAAAic/RBRJdD-wVs4/s1600-h/0.gif
Also, consider that if you write names to an authors field, the you need to use the fully qualified name of the people, otherwise it wouldn't work
If I'm following correctly, the members of the ALL group that are having trouble saving the QCR form, are the ones that are not in the QCR_Access group, correct? That would make sense given that the computed Authors field on the QCR form is set to only allow QCR_Access editing access.
The fix, then, would be to update that document's author field after the user has saved it. You could do that with some sort of agent that runs under a higher-privileged user account. You could also perhaps "hide" the document from the user who creates it until that agent runs, using a reader field.
It's been a while, but I think I opted for a lower-security solution when I faced this, essentially using form events to prevent editing. In that case you can prevent editing when the document is not new, and when the user is not in a certain group. You have to handle the QueryOpen and QueryModeChange events and put the logic there. NOTE: This isn't real security. Authors and Readers fields are the recommended way to handle security for a document.
Hope this helps!
You could make the formula for your authors field look like this:
#If(#IsNewDoc;"All";"QCR_Access");
There is one problem with this, however. If a regular user creates the document, saves it but does not close it, then tries to make changes and save it again, the second save will fail. To deal with that, you could give the users Depositor access and having your querySave code check the Database.CurrentAccessLevel property to see if the current user has Depositor access and prompt the user to ask "Are you sure you want to save? You will not be able to make additional changes."
Create two ACL groups in the Domino Directory (e.g.):
QCR_Editors
QCR_Creators
Put everyone into QCR_Creators, put just yourself and the other editor into QCR_Editors.
In the database access control list (ACL):
Give QCR_Editors "Editor" access (with "Delete documents," if needed.)
Give QCR_Creators "Author" access (with "Create documents" only.)
Note:
You do not need to use Authors or Readers fields on the form or documents.
Creators will have only one oportunity to save the document. Once it is saved, they will be locked out from further edits.
If you need additional functionality (like permitting several saves until done,) let me know.
-- Grant

Can "Excel Add-In for Coded UI Testing" help when reading test scenario data from Excel worksheet

This requires a detailed explanation.
Imagine that I have an Excel spreadsheet with test cases in one worksheet
and I may have expected (validation) messages in another (in addition to expected messages in the first worksheet).
There is also some linking between the values of fields in one to the second worksheets.
See: Welcome, <First Name> <Last Name> as an example.
You can see in the "Expected Results" field in "Test cases" worksheet the value of the field is:
"The user is taken to My Account page and following welcome message is displayed:
"&Messages!$B$1244&", where First name is Dave and Last Name is Brown."
so "&Messages!$B$1244&", denotes field B1244 in worksheet "Messages"
Now the question.
If I am given all test cases like the example below for an ecommerce web site, how can I use Coded UI Testing based on this input? Can I automate Excel, use the steps in test case worksheet and combine that with Coded UI recording of data input and verification.
I believe I would need to do manual coding, partially using recorded input steps and verifications from Coded UI recorder and possibly using manual programming for verification.
I would like to hear if others have done something similar.
I would like to incorporate this into Specflow BDD, by writing feature/user story and these test cases will be scenarios.
Any success, thoughts on using Excel test automation as data driven testing.
Thanks
Rad
Test cases worksheet named "Test cases":
=====================
Test Case Name Test Case Objective
frontstore.01-3 Register a shopper from order
confirmation page with valid inputs
# Step Data Expected Results
------------------------------------------------------------------------------------------------
1 Launch the test storefront http://testserver.com/index Welcome page is loaded.
2 Click Sign In link Sign In page is loaded.
3 Click Register under New Customer Register page is loaded.
4 Enter valid inputs and click Submit "Logon ID = TestUser
Firstname = John
Lastname = Clark
... (other fields) Registration Successful.
The user is taken to My Account page
and following welcome message is displayed:
Welcome, <First Name> <Last Name>, where First name is
David and Last Name is Brown."
Validation Messages worksheet named "Messages":
=====================
#Text used in MyAccountPages
---------------------------------------------------------------------------
MA_WELCOME Welcome, <First Name> <Last Name>
After reading a bit about Coded UI testing:
It can certainly be done, but data/sentences like:
“Launch the test storefront”
“Click Sign In link”
“Registration Successful.
The user is taken to My Account page
and following welcome message is displayed:
Welcome, , where First name is
David and Last Name is Brown."
contain both actions and data so I need to drill down into parts of the sentence to
translate it to actions and binding to parameters.
If I understand well data binding can only be used to bind column values to some parameters.
So I need some way to automatically recognize the meaning of these sentences and use some binding
from parts of it.
So if I have a sentence:
“Launch the test storefront” that would be translated to:
CurrentBrowser.Navigate(Helper.TranslateTargetUrlFrom(“test storefront”))
where “test storefront” might resolve to http://testserver.com/index storefront home
page and I can ignore Data column for URL
or I can capture Launch keyword to mean CurrentBrowser.Navigate(ColumnValue(Data)) and ignore “test storefront” part of the sentence.
“Click Sign In link” could be translated to CurrentBrowser.FindLink(“Sign In”).Click(),
so it this case I will need to know that Sign In is
the text of the link, again I need to extract “Sign In” to mean the text of a link.
I see this as pretty manual style of CodedUI where I could do small recording for some actions and rely on manual extractions of terms from
given sentences.
I would like to know how can I semantically write better test cases to allow automation. I would probably need some kind of free form
test case parser that would recognize the semantic meaning of some words like: click, navigate, launch, enter, click under etc and translate this into
code by re-using existing helper methods and recorded actions and do some manual binding, but not with the whole data value in the column, but
an extracted value.
Any idea of this kind of automation?
I think yould could do this by data binding the input parameters and just reading Excel as a datasource, you are going to need to use CodedUI for that not MTM + Fast Forward

Resources