• 沒有找到結果。

Programming Basics

CHAPTER 3 THE WIS PLATFORM

3.2 Programming Basics

WIS provides all basic needs to create a Web automation application. So there are many things to understand before being able to create applications with WIS.

A WIS application is composed of several pieces working together to accomplish the Web automation needs, which are called WIS components. WIS components are located at the server and downloaded to the WIS client whenever a user starts a Web automation application. Every WIS component is acquired by a URL, so WIS components does not necessarily need to be in a single server; it can be located in different locations, adding more management possibilities.

WIS components can be divided in two distinctly different categories: WIS pages and WIS profiles.

WIS pages are similar to Web pages, with the exception that it contains code proprietary to WIS and cannot be displayed in ordinary Web browsers. Its main function is to provide interface to the user. The first WIS component that a WIS client gets from the server is the WIS application main page. It provides a starting point for the Web automation application, which can do initializations such as downloading WIS profiles. WIS pages can contain HTML, DHTML, JavaScript or Java applets.

WIS profiles are documents encoded with XML and can contain WIS proprietary profiles or profiles specifically designed for the Web automation application. Profiles specified by the developer may contain any information such as setting parameters for the automation application. WIS proprietary profiles instead are for WIS and must follow its definition and may have several different types. At the moment there are only two types: WIS surfing processes and WIS extraction definitions. The WIS surfing process defines the process of interoperation with a resource. The WIS extraction definition tells WIS how to get desired data from pages returned by sources.

In a typical scenario, a Web automation application works as follows. The user first selects a Web automation application by giving the URL of the WIS application main page. Once the application is downloaded, the main page performs initializations, usually downloading the profiles needed. After initialization is finished, the user can interact with the Web automation application interface. The Web automation application will then create WIS sessions as many as needed to accomplish the required task. Every WIS session performs interoperation with a single resource according to the description in the WIS surfing process. A WIS session can also be

used to load other WIS pages from the Web automation application server and display to the user.

3.2.1 Programming Contexts

The programming language used by WIS is JavaScript. But the stateless nature of Web applications and the various WIS components creates different regions of code that have different concerns, which are called programming contexts by this thesis.

The Web automation application developer should be clear about which context he/she is using. There are two programming contexts that originate from the type of the WIS component: WIS pages context and WIS surfing process context. Like JavaScript in Web pages, the developer can expect to have anything that an ordinary browser would provide for scripting, and the lifetime of entities such as functions, variables and objects declared here are only within the page. These two contexts are essentially stateless, since every time the page is reloaded or substituted, user defined entities disappear. Then what can be done to make these entities more persistent when a longer lifetime is needed? WIS provides two more contexts to solve this need. The WIS session context has the lifetime of a WIS session, which supplements the WIS surfing process. When an entity should persist between pages of a surfing process, it can be placed at the WIS session context. Code in the WIS surfing process context can access entities defined in the WIS session context. Another context available is the WIS global context, which exists until the Web automation application terminates.

The WIS global context is accessible by all other contexts.

Context type Page Surfing process Lifetime of Within page Within page Within session Within

entities application Table 3-1: Summary of programming contexts

3.2.2 The WIS Surfing Process

Resources have different interfaces, so when the user uses the browser he/she must

“understand” the interface and make the correct reactions to proceed. The WIS surfing process tells WIS how to manipulate resource page interfaces.

<AutoProcesses StartURL=“starting url“>

<ScriptCode>Session context code</ScriptCode>

<ScriptCodeGlobal>Global context code</ScriptCodeGlobal>

<AP>Page context code

<SP>Frame context code</SP>

<SP>Frame context code</SP>

… </AP>

<AP>Page scope code</AP>

</AutoProcesses>

Figure 3-4: Structure of a WIS Surfing Process

The <AutoProcesses> is the parent element for the definition of a WIS surfing process. The process consists of a series of by page operations. The following are the attributes for the <AutoProcesses> element:

z StartURL: The location of the first page for the entire process.

z Name: Identifier for the WIS surfing process.

z ProxyType: The type of the proxy that will permit connection access to the target resource. The value can be: Default, Direct and Auto.

z ProxyURL: Address of the proxy if type of the proxy is Auto.

The <ScriptCode> element defines code to be executed in the session context. It can be used to initialize variables persistent to the session context, or declare functions.

The <ScriptCodeGlobal> element defines code to be executed in the global context.

Variables and functions persistent to the entire Web application can be declared here.

The <AP> element defines code to be executed for a page of the resource during the surfing process, i.e. the code interoperates with the page. The attributes are:

z Name: Identifier for the step in the surfing process.

z NumberOfFrames: Declares the number of frames if the interface uses frames.

If the page consists of multiple frames, every frame can have its own manipulation code, which can be defined by the <SP> element. The attributes are:

z Name: Identifier.

z FrameIndex: Name of the frame that the code is for. WIS uses it to know which frame will use the given code.

3.2.3 Profile Management

WIS profiles are documents encoded with XML. A single WIS application may consist of many WIS profiles. For convenience, these WIS profiles can be divided in small pieces for development and management convenience. WIS profiles can be placed anywhere. Putting them in the client-side can save download time, especially if there are hundreds of profiles. But frequent updates may be difficult if there are many clients. It is more convenient to have it stored at the server-side and be accessed every time a Web automation application needs.

Multiple profiles can be unified to a single document for easy access from the Web automation application. The UniDoc object does this job. It identifies the

<UniDocInclude> element which is substituted by the demanded profile defined in the Src attribute. By this way, profiles are embedded into parent profiles, forming a single profile for the Web automation application. Parts of the profile then can be obtained by using DOM or XPath.

3.2.4 The WIS API

WIS exposes various functionalities through an API that is called by JavaScript. All extensions provided by WIS are obtained through an object named external. The external object can be obtained from the window object with the following JavaScript code:

var ext = window.external;

What can be accessed directly by the external object is the WIS session context.

For example, if we have a variable called “CommandLine” in the WIS session context, we can obtain its value with the following code:

var val = window.external.CommandLine;

For a function in the WIS session context, the call procedure is similar:

var result = window.external.MyFunction(x);

The WIS global context can be accessed by any other context. We obtain access to it by the GlobalCO object, and its usage is similar to the WIS session context:

var val = window.external.GlobalCO.MyGlobalVariable;

WIS gives access to the rest of the API through the GlobalCO object. Table 3-2 gives a complete list of provided objects at the moment.

Property Description

GlobalCO Global context

UniDoc Provide access to WIS profiles

WMultiWB Provide management facilities for a collection of WIS sessions

WAutoWB WIS session

WMessage Log messages from the Web automation application WBExt Miscelaneous tools are provided by this object Soap Support for Web services

Table 3-2: Objects in WIS

UniDoc provides a centralized manner of using WIS profiles. We prepare it by using the Load method, giving it the location of the main profile, which may include other profiles:

window.external.GlobalCO.UniDoc.Load(MainProfileURL);

WMultiWB is used to manage WIS sessions. To create a new instance of a WIS session, we use the AddSession method:

var oWAutoWB = oWMultiWB.AddSession(SessionName);

The parameter SessionName is a string identifier for the session. AddSession returns an WAutoWB object, which is a WIS session instance. Other methods provided by WMultiWB are:

z Reset(): Method. Destroy all existing WIS sessions, except the main session.

z Scr: Property. This is another way to declare entities in the WIS global context.

The WAutoWB gives us control to a single WIS session. To start a WIS surfing process we first load it into WAutoWB:

oWAutoWB.Load(SurfingProfile);

The parameter SurfingProfile is the XML node of the element <AutoProcesses>.

Then we can execute the given surfing process:

oWAutoWB.Run0();

Other methods and properties provided by WAutoWB are:

z ID: Property. Used to obtain the identifier of the WIS session.

z Navigate(TargetURL): Method. Use it to navigate to the given TargetURL instead of running a WIS surfing process.

z SOnAllDocsCompleted: Event. Write an SOnAllDocsCompleted event handler to be notified whenever a step is accomplished in the WIS surfing process.

z InsertedProcessName: Property. Gives the name of the WIS surfing process used in the WIS session.

WExt provides miscellaneous facilities:

wHTMLGetElementsC ( CollectionOfElements, AttributeConditions): Method.

Search for an element in CollectionOfElements which matches the given AttributeConditions. Find elements in a page returned by a resource.

NewSoap(): Method. Creates a new Soap object.

相關文件