User Tools

Site Tools


Sidebar



en:objects:debug:helper:set_hook

set_hook

set_hook($action,$php_script); - set a hook (execution of an operable script when a certain condition is reached) for a certain action.

the input Function accepts parameters:br>
  • $action – the action on which is placed the hook (condition) :      "unpause" - when you click 'Remove the script with pause'
          "stop" - when you click 'Stop'
          "exitapp" - when receiving a command app->exitapp (since 4.9.21)
         "quit" - when receiving the app->quit command (starting from 4.9.21)
  • $php_script – a script that runs on the specified action

    After testing, the function returns the result of its work to the script :
  • true – the operation was completed successfully
  • true – errors occurred during the operation

    PHP example:

    <?php $xhe_host = "127.0.0.1:7035";
     
    //connect the object to control the emulator, if not already connected
    if(!isset($path))
      $path = "../../../Templates/xweb_human_emulator.php";
    require($path);
     
    //Start
    echo "<hr> <font color = blue> debug->".basename(__FILE__)."</font> <hr>";
     
    //1
    echo "1.Let's set handlers(hooks) for unpause and stop actions:";
    echo $debug->set_hook("unpause", "hook/hook_unpause.php")."";
    echo $debug->set_hook("stop", "hook/hook_stop.php")."<br>";
     
    //message
    $debug->message_box("To start the unpause hook, unpause the script.");
    //pause - after pressing the unplug from the button, hook_unpause.php will be executed
    $app->pause(0);
     
    //2
    echo "2.Get the result of the hook(hook_unpause.php): <br> <br>";
    if($file_os->is_exist("hook/hook_unpause.php.res"))
      echo($textfile->read_file("hook/hook_unpause.php.res"))."<br>";
     
    //message
    $debug->message_box("To start the stop hook, click the stop script button.");
    //long pause
    sleep(5000);
     
    //end
    echo "<hr> <br>";
     
    //Quit
    $app->quit();
    ?>

    Python example:

    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
     
    xhe_host = "127.0.0.1:7017"
    from xweb_human_emulator import *
     
    # Start
    echo("<hr> <font color = blue> debug.xxxxxxxxx </font> <hr>")
     
    # 1
    echo("1.Let's set handlers(hooks) for unpause and stop actions:")
    echo(debug.set_hook("unpause", "hook/hook_unpause.php"), "")
    echo(debug.set_hook("stop", "hook/hook_stop.php"), "<br>")
     
    # message
    debug.message_box("To start the unpause hook, unpause the script.")
    # pause - after pressing the unplug from the button, hook_unpause.php will be executed
    app.pause(0)
     
    # 2
    echo("2.Get the result of the hook(hook_unpause.php): <br> <br>")
    if file_os.is_exist("hook/hook_unpause.php.res"):
        debug.message_box(textfile.read_file("hook/hook_unpause.php.res"))
     
    # message
    debug.message_box("To run the break hook, click the stop script button.")
    #big pause
    sleep(5000)
     
    # end
    echo("<hr> <br>")
     
    # Quit
    app.quit()

    C# example:

    #region using
     
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
     
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
     
    #endregion
     
     class Program: XHEScript
     {
    static void Main(string [] args)
    {
    //init XHE
    server = "127.0.0.1:7010";
    InitXHE();
     
    //Start
    echo("<hr> <font color = blue> debug.clear_tab_content </font> <hr>");
     
     
    //1 step
    echo "1.Let's set handlers(hooks) for unpause and stop actions:";
    echo $debug->set_hook("unpause", "hook/hook_unpause.php")."";
    echo $debug->set_hook("stop", "hook/hook_stop.php")."<br>";
     
    //message
    $debug->message_box("To start the unpause hook, unpause the script.");
    //pause - after pressing the unplug from the button, hook_unpause.php will be executed
    $app->pause(0);
     
    //step 2
    echo "2.Get the result of the hook(hook_unpause.php): <br> <br>";
    if($file_os->is_exist("hook/hook_unpause.php.res"))
      echo($textfile->read_file("hook/hook_unpause.php.res"))."<br>";
     
    //message
    $debug->message_box("To start the stop hook, click the stop script button.");
    //big pause
    sleep(5000);
     
    //end
    echo("<hr> <br>");
     
    app.quit();
    }
    }

    Java Script example:

    //connect the object to control the emulator, if not already connected
    xhe_host = "127.0.0.1:7010";
    echo = require("../../../Templates JS/xweb_human_emulator.js");
     
    //Start
    echo("<hr> <font color = blue> debug.set_hook </font> <hr>");
     
    //1 step
    echo("1.Let's set handlers(hooks) for unpause and stop actions:");
    echo(debug.set_hook("unpause", "hook/hook_unpause.js") + "");
    echo(debug.set_hook("stop", "hook/hook_stop.js") + "<br>");
     
    //message
    debug.message_box("To start the unpause hook, unpause the script.");
    //pause - after pressing the unplug from the button, hook_unpause.php will be executed
    app.pause(0);
     
    //step 2
    echo("2.Get the result of the hook(hook_unpause.php): <br> <br>");
    if(file_os.is_exist("hook/hook_unpause.js.res"))
      echo((textfile.read_file("hook/hook_unpause.js.res")) + "<br>");
     
    //message
    debug.message_box("To start the stop hook, click the stop script button.");
    //big pause
    browser.sleep(5000);
     
    //end
    echo("<hr> <br>");
     
    //Quit
    app.quit();
  • en/objects/debug/helper/set_hook.txt · Last modified: 2026/08/05 22:35 (external edit)