Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Calling TagUI as a webservice / REST service #169

Closed
ramu-yarru opened this issue May 21, 2018 · 12 comments
Closed

Calling TagUI as a webservice / REST service #169

ramu-yarru opened this issue May 21, 2018 · 12 comments
Labels

Comments

@ramu-yarru
Copy link

Hi,
Thank you for the wonderful tool.
I have one question regarding calling TagUI flow as a webservice or REST service. I have deployed the webservice on my webserver(XAMPP->Apache) and hitting the URL you mentioned in the documentation from my browser after including my flow file name in SETTINGS. I am getting the below message in my browser.
[6] ./tagui techforce added into queue
But my flow is not getting triggered. Note that I have set frequency of tagui chrontab to 5 minutes.
Where should I keep my flow file (path on file system) in order for the cron to trigger my flow?
Is there any way to get response from my flow file as a response to the API invocation? If so, could you please throw some light on how can we achieve this.

Thanks,
Ram

@kensoh
Copy link
Member

kensoh commented May 22, 2018

Hi @ramu-yarru thanks for your encouragement. Appreciate your trying out the webservice API feature and raising this question. The default folder to look for flow_filename is tagui/src folder. I've updated readme so that this information is clearer.

Can you check the contents of tagui_service.log to see if the requests are being received? Is there any tagui_service.* files created that may show clues if the crontab job runs correctly?

For returning response directly it is not enabled by design. In order to do something like that, PHP will need command line execution access, but this is not enabled by default and it is a security risk to enable something like that. Thus TagUI webservice is designed to run via crontab periodically instead of returning results immediately.

One way to implement getting results fast is set crontab frequency to be high, and you can output results to some file that is accessible via web browser to check the result from your calling application. Some other ways canl be writing a PHP wrapper to actually use the exec() function to run tagui immediately and return the response.

Lemme know if you run into any issues! Copying @Aussiroth and @lohvht for info.

@kensoh kensoh changed the title Calling TagUI as a webservice/REST service Calling TagUI as a webservice / REST service May 22, 2018
@ramu-yarru
Copy link
Author

Hi @kensoh, thank you for the reply. I can see the following text in tagui_service.in and tagui_service.log files. No errors are recorded in these file except the below text.
[1] ./tagui techforce chrome
[2] ./tagui techforce chrome
[3] ./tagui techforce chrome
[4] tagui techforce chrome
[5] tagui techforce chrome
[6] ./tagui techforce
[7] ./tagui techforce

[1] ./tagui techforce chrome added into queue
[2] ./tagui techforce chrome added into queue
[3] ./tagui techforce chrome added into queue
[4] ./tagui techforce chrome added into queue
[5] ./tagui techforce chrome added into queue
[6] ./tagui techforce added into queue
[7] ./tagui techforce added into queue

My actual requirement is, I need to invoke tagui flow from another program and based on the response returned by the flow, i need to decide which subsequent path to execute. Thats why I am trying to get immediate response from tagui webservice. As you suggested, let me set the crontab frequency to high and test it.

I am curious to know about the alternative option (writing a PHP wrapper to actually use the exec() function) that you have suggested since it is more relevant to my use case as it returns immediate response. But unfortunately I have very basic knowledge on PHP, so could you please elaborate in detail on this option (like writing a PHP wrapper to use exec() function)

Thanks,
Ram

@kensoh
Copy link
Member

kensoh commented May 23, 2018

I see.. For instant results, see the example below (using this stackoverflow example) -

service.php

<?php
  
$out = array();
exec("tagui demo", $out);
foreach($out as $line) {
    echo $line . "\n";
}

?>

demo

py begin
a = 1
b = 2
c = a + b
print(c)
py finish
echo py_result

js begin
a = 1
b = 2
c = a + b
js finish
echo c

dom begin
a = 1
b = 2
c = a + b
return c
dom finish
echo c

when you run php service.php

108-95:Desktop kensoh$ php service.php 

START - automation started - Wed May 23 2018 11:13:54 GMT+0800 (+08)

py a = 1
py b = 2
py c = a + b
py print(c)
3
3
3

FINISH - automation finished - 0.9s

@kensoh
Copy link
Member

kensoh commented May 23, 2018

Adding to above, you can then use quiet option to control the exact output of what you want to be returned. And proper PHP syntax such as below to receive parameters from your webservice URL -

$service_settings = $_GET['SETTINGS'];

For example, calling https://xxx.com/service.php?SETTINGS=demo will throw in the demo string as a variable to be used in the service.php script and then return the execution output.

Closing the issue for now, but please keep your questions coming if you run into anything!

Tagging @Aussiroth and @lohvht for info.

@kensoh kensoh closed this as completed May 23, 2018
@ramu-yarru
Copy link
Author

Hi Ken,

Thank you for the reply. As you suggested above, I am calling my TagUI flow by the following URL
http://localhost/service.php?SETTINGS="demo chrome"
And below is my service.php file

**<?php

$service_settings = $_GET['SETTINGS'];
$out = array();
exec('tagui'.' '.$service_settings, $out, $return_var);
if($return_var !== 0){
echo "failed";
}
else{
echo "passed";
}

?>**

Unfortunately, this is not working if I pass two parameters (for example: demo chrome) for SETTINGS in the URL. It perfectly works fine if I pass one parameter for SETTINGS.

I even tried splitting the parameters into two variables using explode function, but that also didn't work for me. $service_settings variable PHP exec is not accepting more than one parameter. Could you please suggest here.

Thanks,
Ramu

@kensoh
Copy link
Member

kensoh commented May 30, 2018

Hi @ramu-yarru when the settings has "" it may need to trim away, you can try using something like below to see if that works for filename + option(s) -

<?php

$service_settings = $_GET['SETTINGS'];
$service_settings = trim($service_settings, '"');
$out = array();
exec('tagui'.' '.$service_settings, $out, $return_var);
if($return_var !== 0){
echo "failed";
}
else{
echo "passed";
}

?>

Copying @Aussiroth @lohvht for info -

@snapSnp
Copy link

snapSnp commented Oct 9, 2019

Hi @kensoh,
Am facing a similar issue , even i have deployed tagui on my webserver(XAMPP->Apache) on hitting the below URL in the my browser, a new chrome browser is launched and then it crashes .
URL : http://localhost/tagui/src/tagui_service.php?SETTINGS=C://xampp//htdocs//tagui/src/code/UserCreationFiles/TC_CD_R001_1/TC_CD_R001_1.txt%20C://xampp//htdocs//tagui/src/code/UserCreationFiles/TC_CD_R001_1/TC_CD_R001_1.csv%20chrome%20test

I can see the following text in tagui_service.log files. No errors are logged in these file except the below text.
[1] ./tagui C://xampp//htdocs//tagui/src/code/UserCreationFiles/TC_CD_R001_1/TC_CD_R001_1.txt C://xampp//htdocs//tagui/src/code/UserCreationFiles/TC_CD_R001_1/TC_CD_R001_1.csv chrome test added into queue
[2] ./tagui C://xampp//htdocs//tagui/src/code/UserCreationFiles/TC_CD_R001_1/TC_CD_R001_1.txt C://xampp//htdocs//tagui/src/code/UserCreationFiles/TC_CD_R001_1/TC_CD_R001_1.csv chrome test added into queue

in service.php have added the below code :
<?php
$service_settings = $_GET['SETTINGS'];
$out = array();
exec('tagui'.' '.$service_settings, $out, $return_var);
print('tagui'.' '.$service_settings);
print_r($return_var);
?>

I am trying to invoke the tagui script in TC_CD_R001_1.txt file.

Thanks,
Syed

@kensoh
Copy link
Member

kensoh commented Oct 10, 2019

Hi Syed, thanks for the details. Can you check 2 things to see if they help?

  1. Rename your script to something else instead of test, because test is a special keyword to run test automation mode, which is not the use case here

  2. Double check to make sure PHP on your server has permissions to run the exec() command. You can check that by running something simple to see if the command is executed. I am guessing it is enabled that is why Chrome launches.

Let me know how it goes!

@snapSnp
Copy link

snapSnp commented Oct 10, 2019

Hi Syed, thanks for the details. Can you check 2 things to see if they help?

  1. Rename your script to something else instead of test, because test is a special keyword to run test automation mode, which is not the use case here
  2. Double check to make sure PHP on your server has permissions to run the exec() command. You can check that by running something simple to see if the command is executed. I am guessing it is enabled that is why Chrome launches.

Let me know how it goes!

Hi Kensoh,

Thanks for your reply.
Script is named as TC_CD_R001_1.txt not 'test' , 'test' is used to do the assertions. I removed the test keyword and hit the below URL as well. But the result is same , new browser instance is launched and gets closed without any error logs. Also this time 'added into queue' log is not generated in tagui_service.log files
URL : http://localhost/tagui/src/tagui_service.php?SETTINGS=C://xampp//htdocs//tagui/src/code/UserCreationFiles/TC_CD_R001_1/TC_CD_R001_1.txt%20C://xampp//htdocs//tagui/src/code/UserCreationFiles/TC_CD_R001_1/TC_CD_R001_1.csv%20chrome
The exec() command is working on server.

Thanks
Syed

@kensoh
Copy link
Member

kensoh commented Oct 10, 2019

I see.. Try the following to see if there are more clues -

  1. check the folder containing the scrip to see the log file TC_CD_R001_1.txt.log if there is any clues why the execution halted

  2. check in your tagui installation folder, tagui/src/tagui_chrome.log to see what is inside the Chrome log file

  3. Write a simple script just to echo '123' and then run that script as a webservice, to see if the error is due to the handling of CSV file or some other reasons. I have not tested the web-service functionality exhaustively because it is not a feature used by most users, so it could be issue working with datatable, or some other causes not discovered when doing simple tests during the development of the feature.

@snapSnp
Copy link

snapSnp commented Oct 11, 2019

Hi Kensoh,
Thanks for you response , I was able to proceed and i was able to run my test case with the below API-1-URL.
API -1-URL
http://localhost/tagui/src/tagui_service.php?SETTINGS=C://xampp//htdocs//tagui/src/code/UserCreationFiles/TC_CD_R001_1/TC_CD_R001_1.txt%20C://xampp//htdocs//tagui/src/code/UserCreationFiles/TC_CD_R001_1/TC_CD_R001_1.csv%20chrome%20test

API -2-URL
http://localhost/tagui/src/tagui_service.php?SETTINGS=C://xampp//htdocs//tagui/src/code/UserCreationFiles/TC_CD_R001_2/TC_CD_R001_2.txt%20C://xampp//htdocs//tagui/src/code/UserCreationFiles/TC_CD_R001_2/TC_CD_R001_2.csv%20chrome%20test

The issue that am facing now is when i call the above API-1 , new chrome browser is launched and the test execution starts, simultaneously when i call above API-2 for another test case, new chrome browser is launched but the chrome browser launched by API-1 is closed without completing the test case execution.
Need your help on this.

Thanks
Syed

@kensoh
Copy link
Member

kensoh commented Oct 11, 2019

Hi Syed, I suspect you may not be using this as intended. From documentation, it is implemented with crontab to call tagui_crontab. This allows the service to add items into the queue using the tagui_service.php that comes with TagUI, to be executed on a periodic basis set in crontab -

From documentation, https://github.com/kelaberetiv/TagUI#api

By using the setup in above documentation, the service will check the queue to run only 1 instance at a time and not expected to run multiple automation processes at the same time.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants