using watin to automate business objects reports - watin

how can i use watin to test business object reports in case all page render auto generated every run as the following
iD="generated number"+_string text
text field ID="12213124_sadfafs";

Assuming your string (eg: sadfafs) is known, use a RegEx for the Find parameter.
Something like: Find.ById(new Regex(regex_for_ends_with_sadfafs))

Related

Combining two xpaths into one xpath

Is it possible to combine these two Xpaths into one xpath query?
signatureAgreementThumbnailForInProgressApplication = By.XPath("//div[text()='Upload Signature Agreement']/parent::div/parent::div/descendant::div[contains(#style,'background-image: url')]");
signatureAgreementThumbnailForSubmittedApplication = By.XPath("//div[text()='Signature Agreement']/parent::div/descendant::div[contains(#style,'background-image: url')]");
My automation test (project is VS/C#/Selenium) requires validating the presence (but not content or anything else) of document thumbnails for two statuses of an online application: in-progress and submitted. I feel two separate methods with different xpaths is redundant, since I am doing the same simple validation.
After looking through SO posts which suggested using and/or to evalute multiple attributes, I created this below query which works almost perfectly for both In-Progress and Submitted thumbnails. Minor issue is that for Submitted, in DOM, the xpath hits two thumbnail elements, the one I want it to hit and another one. My test still passes since it is validating thumbnail presence, but I am hoping to tweak it so it finds the specific thumbnail.
signatureAgreementThumbnail = By.XPath("//div[text()='Upload Signature Agreement' or text()='Signature Agreement']/parent::div/parent::div/descendant::div[contains(#style,'background-image: url')]");
I also tried the following queries, which do not work at all:
//div[text()='Upload Signature Agreement' or text()='Signature Agreement'][/parent::div/parent::div/descendant::div or /parent::div/descendant::div][contains(#style,'background-image: url')]
//div[text()='Upload Signature Agreement' or text()='Signature Agreement'][/parent::div/parent::div/descendant::div or /parent::div/descendant::div and contains(#style,'background-image: url')]
I cannot provide the URL of the site I am automating since it is a private site.

UFT: Problem in extracting data from excel file and input in the application dynamically

I am facing issues in performing certain actions based on the value in the excel file cell data.
Actions like if value is "NORMAL" then click Container type = Normal (radio button)
Similarly the Unit Container Value
Following is my code:
I am getting this error while performing action .WebElement("Container_Type_Normal").Click
Your error is because you can't start a line with . unless your within a with - and i can't see a with in your function. (i also don't recommend using a with as the can cause needless confusion)
The .webelement object is a catch-all type of object that is the child of other web objects or .page. You need this to be a full and valid path to the object, by this i mean start with browser().page().
You have a couple of options:
You can either make this a full path to your object based on the object repository:
Browser("<<OR Browser name>>").Page("<<OR Page name>>").WebElement("<<Your webelement name>>".click
For this, look at your OR and insert your names.
Or, option 2, you can use descriptive programming:
Browser("CreationTime:=0").Page("index:=0").WebElement("text:=" & fieldValue,"index:=0").click
That will take the browser that was created first (Creation time 0), the only page it has and the first (index 0) web element that contains your text (text is field value).
I'm assuming that you only have one browser, and that the first element that contains the text you want is what you want to click. You may need to add more layers too this or
A good approach is to mirror what is OR or use the object spy to ensure these properties are correct.

How to get the actual Hyperlink element inside the main document part using docx4j

So I have a case where I need to be able to work on the actual Hyperlink element inside the body of the docx, not just the target URL or the internal/externality of the link.
As a possible additional wrinkle this hyperlink wasn't present in the docx when it was opened but instead was added by the docx4j-xhtmlImporter.
I've iterated the list of relationships here: wordMLPackage.getMainDocumentPart().getRelationshipsPart().getRelationships().getRelationship()
And found the relationship ID of the hyperlink I want. I'm trying to use an XPath query: List<Object> results = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:hyperlink[#r:id='rId11']", false);
But the list is empty. I also thought that it might need a refresh because I added the hyperlink at runtime so I tried with the refreshXMLFirst parameter set to true. On the off chance it wasn't a real node because it's an inner class of P, I also tried getJAXBAssociationsForXPath with the same parameters as above and that doesn't return anything.
Additionally, even XPath like "//w:hyperlink" fails to match anything.
I can see the hyperlinks in the XML if I unzip it after saving to a file, so I know the ID is right: <w:hyperlink r:id="rId11">
Is XPath the right way to find this? If it is, what am I doing wrong? If it's not, what should I be doing?
Thanks
XPathHyperlinkTest.java is a simple test case which works for me
You might be having problems because of JAXB, or possibly because of the specific way in which the binder is being set up in your case (do you start by opening an existing docx, or creating a new one?). Which docx4j version are you using?
Which JAXB implementation are you using? If its the Sun/Oracle implementation (the reference implementation, or the one included in their JDK/JRE), it might be this which is causing the problem, in which case you might try using MOXy instead.
An alternative to using XPath is to traverse the docx; see finders/ClassFinder.java
Try without namespace binding
List<Object> results = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//*:hyperlink[#*:id='rId11']", false);

How to add components in to an existing GUI created by guide?

I just created a GUI using guide in MATLAB for a small project I'm working on. I have amongst other things two text fields for from and to dates. Now I'd like to get rid of them and use a Java date select tool. Of course this is not possible using guide so I need to add them manually.
I've managed to get them to show up by putting this code into my Opening_Fcn,
uicomponent(handles, 'style','com.jidesoft.combobox.DateChooserPanel','tag','til2');
using UICOMPONENT.
But even though it shows up I can't access the date select's attributes, for example
get(handles.til2)
returns
??? Reference to non-existent field 'til2'.
How can I fix this?
Unless you edit the saved GUI figure, the basic handles structure will not include your new component by default.
One way to access you component is to store the handle via guidata, by adding the following to your opening function:
handles.til2 = uicomponent(handles, 'style','com.jidesoft.combobox.DateChooserPanel','tag','til2');
guidata(hObject,handles)
Functions that need to access the handle need the line
handles = guidata(hObject)
to return the full handles structure that includes the filed til2

Best way to associate data files with particular tests in RSpec / Ruby

For my RSpec tests I would to automatically associate data files with each test. To clarify, if my tests each require an xml file as input data and then some xpath statements to validate the responses they get back I would like to externalize the xml and xpath as files and have the testing framework easily associate them with the particular test being run by using the unique ID of the test as the file(s) name. I tried to get this behavior but the solution isn't very clean. I wrote a helper method that takes the value of "description" and combines it with FILE to create a unique identifier which is set into a global variable that other utilities can access. The unique identifier is used to associate the data files I need. I have to call this helper method as the first line of every test, which is ugly.
If I have an RSpec example that looks like this:
describe "Basic functions of this server I'm testing" do
it "should give me back a response" do
# Sets a global var to: "my_tests_spec.rb_should_give_me_back_a_response"
TestHelper::who_am_i __FILE__, description
...
end
end
Is there some better/cleaner/slicker way I can get an unique ID for each test that I could use to associate data files with? Perhaps something build into RSpec I'm unaware of?
Thank you,
-Bill
I just learned about the nifty global before and after hooks. I can hide the unique ID creation code there. It makes things much cleaner. I'll probably go with this solution unless there's an even slicker way to acquire a unique ID for each test. Thanks

Resources