0

How to debug zk

asked 2022-10-03 21:55:13 +0800

rawas gravatar image rawas
3 1

I have script which on button press downloading file domain.com/zkau/view/z8/dwnmed-0/0ej1/File.xlsx always changing this part z8/dwnmed-0/0ej1/

Questions: 1. How to find which script code and how forming download url? 2. how catch this url in chrome console? 3. How debug such things?

delete flag offensive retag edit

5 Answers

Sort by ยป oldest newest most voted
0

answered 2022-10-04 18:45:01 +0800

MDuchemin gravatar image MDuchemin
2298 1 5
ZK Team

updated 2022-10-04 18:47:17 +0800

There is a lot to talk about for selenium testing :)

Regarding finding components by IDs, there are 2 different ID sets. Client-side IDs are generated by an IdGenerator (which you can replace by a custom one if you want consistent client-side IDs), and server-side IDs set on your components are the same between page refreshes.

For example, if you define a button in zul:

<button id="myBtn" label="foo"/>
(or in java new Button(); btn.setId("myBtn"); etc.)

ZK will generate the client-side dom element for this button:

<button type="button" id="xyz123" class="z-button"...>foo</button>

the ID at client-side (xyz123) is the component's UUID. The ID at server-side (myBtn) is the component's ID.

You can use either to retrieve the component's dom node at client-side: zk.$('#xyz123').$n() //retrieves DOM node by client-side ID (UUID) zk.$('$myBtn').$n() //retrieves DOM node by server-side ID

Now, I don't know how the links which you need to click are generated in your application, but if you can give them a server-side ID (which stays the same between refreshes), you can just check if there is a component with that ID, and just do something like widgetExists = zk.$('$myLinkId') != null; to check if it exists currently

otherwise, selenium's waitForElementPresent is not a bad choice if you implement a custom IdGenerator

Regarding all of that, plus waiting for the scripts, the timing and processing, there is already more information in this article than what I'd be able to write here: https://www.zkoss.org/wiki/SmallTalks/2013/July/ZKTestingwithSeleniumIDE#Waitingfor_AJAX

Edit: regarding the error screenshot, are you using the server-side ID? that looks like a client-side UUID, which you can also select for, but using # instead of $. (see the selector doc in my previous answer) Anyway, as I mentioned client-side UUID is less useful since it refreshes with the page, unless you implement a custom ID generator

link publish delete flag offensive edit
0

answered 2022-10-04 15:02:01 +0800

MDuchemin gravatar image MDuchemin
2298 1 5
ZK Team

Hey there Rawas,

First question would be "what are you trying to debug"?

The zkau URI is a hash of the ZK version of the application and a few other things.

Regarding file download, if you have a page using ZK which downloads a files to the browser, the best way to do so is to use FileDownload: https://www.zkoss.org/wiki/ZKComponentReference/Essential_Components/Filedownload

The Filedownload feature just accepts a downloadable at server side, and does all of the required URL wiring for you. There is usually not reason for you to change these URLs, unless you have a very specific requirement.

In general, what are you trying to do? :) There is probably an already packaged way to do it regarding file download.

link publish delete flag offensive edit
0

answered 2022-10-04 17:56:03 +0800

rawas gravatar image rawas
3 1

im trying to automate downloading process, so clicking on link with selenium is not perfect solutions, so i want to get direct links from downloadable files

link publish delete flag offensive edit
0

answered 2022-10-04 18:09:49 +0800

MDuchemin gravatar image MDuchemin
2298 1 5
ZK Team

Alright, so your use case is that you want to check that the file is available while doing selenium testing?

If you just want to access a document from server-side, then the easiest option is to just have that document under the webapp folder. For example, if you put your file at /webapp/resources/myfile.xlsx, then it will be available at the url /yourapplication/resources/myfile.xlsx

However, in that case it is a direct download, and it's not testing your actual file download.

But in any case, if you are testing a ZK action which triggers a file download, the easiest option would be to trigger that action in the first place. If you put a selector on the zk button (or other component) which trigger the event, which in turn causes the filedownload, you should be getting the file in return.

I suggest reading up on zk object selection if you want to streamline your test cases ;) https://www.zkoss.org/wiki/ZKClient-sideReference/GeneralControl/Client-sideselectionofelementsandwidgets See this chapter: Zk widget DOM node selection

you can simply select a button's DOM node with "zk.$('$myBtnId').$n()" and trigger a seleniun click on it.

link publish delete flag offensive edit
0

answered 2022-10-04 18:27:22 +0800

rawas gravatar image rawas
3 1

updated 2022-10-04 18:36:37 +0800

Also your code give me an error "zk.$('$myBtnId').$n()"

i.ibb.co/hXn6WCY/image.png

but how i can select node if it always changing his ID it dinamically changing, and POST data ID differs from form button ID

To download file from page (all thing only on client side) i need first press xlsx generation button, then wait some times and after press on each generated xlsx link. but xlsx link also dinamicaly formated on the fly throught hundred of methods and checks zkmx, zkme, zkx first event handled on

    if (!(b9 = cb.handle)) {
      b9 = cb.handle = function (ci) {
        return typeof bH !== az && (!ci || bH.event.triggered !==
        ci.type) ?
        bH.event.dispatch.apply(b9.elem,
        arguments) : aD
      };
      b9.elem = b5
    }

then

function B(W, X) {
  if (!X) {
    X = 0
  }
  if (W && X >= 0) {
    setTimeout(function () {
      zAu.sendNow(W)
    }, X)
  }
}

then

function f() {
  var i = b();
  if (i != d) {
    d = i;
    zAu.send(new zk.Event(null, 'onBookmarkChange', i), 50);
    zk.bmk.onURLChange()
  }
}

then

function x() {
  e(zk.processMask)
}

function f(z, y) {
  return function () {
    return y.apply(z, arguments)
  }
}

function G() { var ac = b, ad = P, W; try { if (ac && ac.readyState == 4) { b = P = null; if (zk.pfmeter) { zAu._pfrecv(ad.dt, s(ac)) } W = ac.getResponseHeader('ZK-SID'); var Y; if ((Y = ac.status) == 200) {

...etc

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2022-10-03 21:55:13 +0800

Seen: 10 times

Last updated: Oct 04

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More