Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
vikas2
Active Participant

This wiki link already covers how to extract information from ESR / ID objects . This works fine for checking a single object. However, sometimes we may need to extract metadata of all PI objects ( for instance, to find all objects modified after a certain date ) or even analyse the source code ( to find all objects using a certian Java function / Value map ).

Through this blog, I'll show how we can automate reading SimpleQuery.

Looking at the SimpleQuery structure in terms of HTML pages in the below image, the information we need is in the step highlighted in the Green box below.

How to automate filling this information ?

Here we'll use HtmlUnit. From it's homepage link description : HtmlUnit is a "GUI-Less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc... just like you do in your "normal" browser.

For our example, we're interested in filling up the below page.

We will need to run some tests to see what the default values are for each of the fields.

The general sequence of steps is:

- Create an instance of WebClient

WebClient webClient = new WebClient();

- Encode {username:password} using base 64 encoding and update the header


  setCredentials(webClient);


It can be implemented as


private static void setCredentials(WebClient _webClient) {

  String base64encodedUsernameAndPassword = base64Encode(combinePasswd);

  _webClient.addRequestHeader("Authorization", "Basic "

  + base64encodedUsernameAndPassword);

  }

- Create an instance of HtmlPage and get the form by checking the body

HtmlPage currentPage = webClient.getPage(url);

HtmlForm form = (HtmlForm) currentPage.getByXPath("/html/body/form").get(0);

- Once we have the form, select different objects, set/ unset values

// Get SWC

  HtmlRadioButtonInput choseSWC = form

  .getInputByValue("All software components");

  choseSWC.click();

//Unclick changeList User

HtmlCheckBoxInput changeListUser = form.getInputByName("changeL");

changeListUser.click();

- Click the Start Query button to get the result page.

HtmlSubmitInput submit = form.getInputByValue("Start query");

HtmlPage resultPage = submit.click();

This page will have all the links and we can convert it nicely to a String.

String resultPageText = resultPage.asXml().toString();

I wanted to keep this blog brief to focus on automating getting the result page.

This github link has the source code. Please make sure you have HtmlUnit library added to your project. You can run the source code - just adapt the static variables in the beginning of the file - SimpleQuery url , user and password.

We can now build up this knowledge to get more information. I'll take two use cases:


Compare map versions between two PI systems.


- Extract graphical maps using value mappings.

1 Comment
Labels in this area