Command to retrieve browser URL in sikuli script - sikuli

I am working on a testing tool and am using Sikuli to emulate user requests to the web application.
Is there a way for me to retrieve the url in the browser address bar (after clicking on a specific link) ?
Any help, pointers into documentation would be greatly appreciated
Cheers!

There is no way to do this in Sikuli. I could recommend you use Selenium. It is the best framework for web testing.

I'd do this with keystrokes. Select all, copy-paste using the clipboard.
click("url.png" ) # select the url location; may be a bit iffy/browser dependent
type("a", KEY_CTRL) # select all
type("c", KEY_CTRL) # copy to clipboard
click("target.png" ) # go to your target
type("v", KEY_CTRL) # and paste
Reference:
http://doc.sikuli.org/keys.html

Simple solution
click(your link);sleep(2) # or wait for loading to finish via an exists()
type("l",Key.CTRL) # hotkey for address bar selection on FF and GC
type("c",Key.CTRL) #copies

You could use the command : type("c", key modifier.CTRL) and after the command: App.get Clipboard(). The commando App.getClipboard get the text of your clipboard and you could save this text one object or variable for use later. (Sorry my english kkk)

Related

Zabbix and HP OpenView integration

Did someone ever set up Zabbix to work with HP OpenView ?
Zabbix docs doesn't mention much information on that.
I know I have to create a media linked to a script.
In that script I have to use the opcmsg command but I don't understand the part which involves the database.
Can someone who ever experienced it drives me to the solution ?
Regards
You are missing media script doc. Parse input in your media script and process it with 'opcmsg'.
Try to find similar alert scripts (concept, not code) for your inspiration - https://www.zabbix.com/documentation/3.0/manual/config/notifications/media/script
And finally please publish your script with documentation (I recommend Github + Zabbix share).
Finally we have decided to create a media script which is writing output to a file.
Then that file will be monitored by a HP OpenView agent.
The steps are the following:
Create media script which is referencing your script :
In my case the script is named hpov.sh
The location of your script has to be referenced in your server config file (zabbix_server.conf) this way : AlertScriptsPath=/path/to/zabbix/scripts
Create an action which will be triggered on problems. Specify the macro you want in the first tab. The condition you want in the second one (leave as default). And finally set the third tab "Operations" like that:
You are free to change Users who are concerned
As the documentation says, link that media script to a user of your choice
That's it !

Disable Chrome address bar autosearch for dev

Developing a web app locally and I just can't get Chrome to actually go to this address, because auto search always kicks in (http://0.0.0.0:5000/api works though, for example).
Is there a way to overwrite this behaviour or force Chrome to try a http request first, before anything else?
I am aware I can just curl it or whatever to see the response...
Go to chrome://omnibox/ and check [x] Prevent inline autocomplete
The answer to this has to be in chrome://chrome-urls
you should see something like the following:
The "full" set of settings is on the chrome://chrome-urls . Also chrome://flags is worth to check. As a side by enabling some experimental features from chrome://flags you can greatly enhance your browsers HTML5 support which can be checked at HTML 5 support .
else:
Clear browser historythen go to settings and under Privacy --> uncheck [] Use a prediction service to help complete searches and URLs typed in the address bar .
Another idea is to examine carefully if using linux the output of the following command for parameters:
ps -aux | grep google-chrome-stable
in my case the output tells me a lot about what parameters are used at launch by default:
/opt/google/chrome/chrome --type=renderer --disable-layer-squashing --enable-transition-compositing --enable-deferred-image-decoding --enable-display-list-2d-canvas --enable-distance-field-text --enable-encrypted-media --enable-experimental-canvas-features --enable-experimental-web-platform-features --enable-lcd-text --enable-one-copy --enable-overlay-scrollbar --enable-renderer-mojo-channel --enable-smooth-scrolling --enable-viewport-meta --enable-webgl-draft-extensions --enable-web-midi --enable-zero-copy --max-tiles-for-interest-area=512 --enable-plugin-power-saver --lang=en-US --force-fieldtrials=AutoReloadExperiment/FlagEnabled/AutoReloadVisibleOnlyExperiment/FlagEnabled/ChromeSuggestions/Default/DomRel-Enable/enable/EnhancedBookmarks/Default/ExtensionContentVerification/Enforce/ExtensionInstallVerification/None/GCM/Enabled/MaterialDesignNTP/Enabled_forced/OmniboxBundledExperimentV1/StandardR4/PasswordGeneration/Disabled/PrerenderFromOmnibox/OmniboxPrerenderEnabled/QUIC/FlagEnabled/SafeBrowsingIncidentReportingService/Default/SettingsEnforcement/no_enforcement/UMA-Dynamic-Binary-Uniformity-Trial/default/UMA-Population-Restrict/normal/UMA-Uniformity-Trial-1-Percent/group_09/UMA-Uniformity-Trial-10-Percent/group_02/UMA-Uniformity-Trial-100-Percent/group_01/UMA-Uniformity-Trial-20-Percent/group_04/UMA-Uniformity-Trial-5-Percent/group_16/UMA-Uniformity-Trial-50-Percent/group_01/UwSInterstitialStatus/OnButInvisible/VoiceTrigger/Install/WebRTC-IPv6Default/Default/ --enable-crash-reporter=9F2AFD26-85F1-40CB-991F-0980EF2C4D14 --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --enable-offline-load-stale-cache --enable-app-window-controls --enable-embedded-extension-options --enable-experimental-extension-apis --enable-scripts-require-action --enable-nacl --enable-nacl-debug --enable-streamlined-hosted-apps --enable-web-based-signin --javascript-harmony --out-of-process-pdf --enable-delegated-renderer --enable-impl-side-painting --num-raster-threads=4 --enable-gpu-rasterization --channel=5035.27.2136067136
Even yet another idea is maybe to write a small widget using python's tkinter and the webrowser modules, it could even get its input from the clipboard.
this command could be a work around solution too:
python -m webbrowser -t "http://ip.ip.ip.ip:portport/file/"
Another option yet is to use The Omnibox API and embed a custom omnibox in a simple webpage. Here are the omnibox api ready made samples.
You can avoid this by adding a "/" at the end of the URL http://0.0.0.0:5000/api/
or
You can try to add a null search engine with a URL of http://%s and null keyword.
Go to the search engine settings:
Open Settings.
Click Manage search engines
At the bottom of the Other search engines section add a new search engine.
Using #Juan Buhagiar answer as a starting point, I added your URL as the URL of a default search engine:
Other search engines
| MyAPI | 0.0.0.0 | http://0.0.0.0:5000/api/venues/show/45/20/cafes?rubbish=%s |
That just worked. The only drawback is that you get a redundant query to your request:
http://0.0.0.0:5000/api/venues/show/45/20/cafes?rubbish=0.0.0.0%3A5000%2Fapi%2Fvenues%2Fshow%2F45%2F20%2Fcafes%2F
instead of plain:
http://0.0.0.0:5000/api/venues/show/45/20/cafes
So as long as it does not conflict with your own GET, you can just ignore it.
Simplest way - Add a bookmark with your desired address. This time it will not goto search. This may not be useful if you have to change variables regularly, which was not my case.
This is helpful if you do not want it to disable omnibar search completely since it is quite a useful feature.

Save the console.log in Chrome to a file

Does anyone know of a way to save the console.log output in Chrome to a file? Or how to copy the text out of the console?
Say you are running a few hours of functional tests and you've got thousands of lines of console.log output in Chrome. How do you save it or export it?
Good news
Chrome dev tools now allows you to save the console output to a file natively
Open the console
Right-click
Select "save as.."
Chrome Developer instructions here.
I needed to do the same thing and this is the solution I found:
Enable logging from the command line using the flags:
--enable-logging --v=1
This logs everything Chrome does internally, but it also logs all the console.log() messages as well. The log file is called chrome_debug.log and is located in the User Data Directory which can be overridden by supplying --user-data-dir=PATH (more info here).
Filter the log file you get for lines with CONSOLE(\d+).
Note that console logs do not appear with --incognito.
I have found a great and easy way for this.
In the console - right click on the console logged object
Click on 'Store as global variable'
See the name of the new variable - e.g. it is variableName1
Type in the console: JSON.stringify(variableName1)
Copy the variable string content: e.g. {"a":1,"b":2,"c":3}
Go to some JSON online editor:
e.g. https://jsoneditoronline.org/
There is an open-source javascript plugin that does just that, but for any browser - debugout.js
Debugout.js records and save console.logs so your application can access them. Full disclosure, I wrote it. It formats different types appropriately, can handle nested objects and arrays, and can optionally put a timestamp next to each log. You can also toggle live-logging in one place, and without having to remove all your logging statements.
For better log file (without the Chrome-debug nonsense) use:
--enable-logging --log-level=0
instead of
--v=1 which is just too much info.
It will still provide the errors and warnings like you would typically see in the Chrome console.
update May 18, 2020: Actually, I think this is no longer true. I couldn't find the console messages within whatever this logging level is.
This may or may not be helpful but on Windows you can read the console log using Event Tracing for Windows
http://msdn.microsoft.com/en-us/library/ms751538.aspx
Our integration tests are run in .NET so I use this method to add the console log to our test output. I've made a sample console project to demonstrate here: https://github.com/jkells/chrome-trace
--enable-logging --v=1 doesn't seem to work on the latest version of Chrome.
For Google Chrome Version 84.0.4147.105 and higher,
just right click and click 'Save as' and 'Save'
then, txt file will be saved
A lot of good answers but why not just use JSON.stringify(your_variable) ? Then take the contents via copy and paste (remove outer quotes). I posted this same answer also at: How to save the output of a console.log(object) to a file?
There is another open-source tool which allows you to save all console.log output in a file on your server - JS LogFlush (plug!).
JS LogFlush is an integrated JavaScript logging solution which include:
cross-browser UI-less replacement of console.log - on client side.
log storage system - on server side.
Demo
If you're running an Apache server on your localhost (don't do this on a production server), you can also post the results to a script instead of writing it to console.
So instead of console.log, you can write:
JSONP('http://localhost/save.php', {fn: 'filename.txt', data: json});
Then save.php can do this
<?php
$fn = $_REQUEST['fn'];
$data = $_REQUEST['data'];
file_put_contents("path/$fn", $data);
Right-click directly on the logged value you want to copy
In the right-click menu, select "Store as global variable"
You'll see the value saved as something like "temp1" on the next line in the console
In the console, type copy(temp1) and hit return (replace temp1 with the variable name from the previous step). Now the logged value is copied to your clipboard.
Paste the values to wherever you want
This is especially good as an approach if you don't want to mess with changing flags/settings in Chrome and don't want to deal with JSON stringifying and parsing etc.
Update: I just found this explanation of what I suggested with images that's easier to follow https://scottwhittaker.net/chrome-devtools/2016/02/29/chrome-devtools-copy-object.html
These days it's very easy - right click any item displayed in the console log and select save as and save the whole log output to a file on your computer.
On Linux (at least) you can set CHROME_LOG_FILE in the environment to have chrome write a log of the Console activity to the named file each time it runs. The log is overwritten every time chrome starts. This way, if you have an automated session that runs chrome, you don't have a to change the way chrome is started, and the log is there after the session ends.
export CHROME_LOG_FILE=chrome.log
the other solutions in this thread weren't working on my mac. Here's a logger that saves a string representation intermittently using ajax. use it with console.save instead of console.log
var logFileString="";
var maxLogLength=1024*128;
console.save=function(){
var logArgs={};
for(var i=0; i<arguments.length; i++) logArgs['arg'+i]=arguments[i];
console.log(logArgs);
// keep a string representation of every log
logFileString+=JSON.stringify(logArgs,null,2)+'\n';
// save the string representation when it gets big
if(logFileString.length>maxLogLength){
// send a copy in case race conditions change it mid-save
saveLog(logFileString);
logFileString="";
}
};
depending on what you need, you can save that string or just console.log it and copy and paste. here's an ajax for you in case you want to save it:
function saveLog(data){
// do some ajax stuff with data.
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200) {}
}
xhttp.open("POST", 'saveLog.php', true);
xhttp.send(data);
}
the saveLog.php should append the data to a log file somewhere. I didn't need that part so I'm not including it here. :)
https://www.google.com/search?q=php+append+to+log
This answer might seem specifically related, but specifically for Network Log, you can visit the following link.
The reason I've post this answer is because in my case, the console.log printed a long truncated text so I couldn't get the value from the console. I solved by getting the api response I was printing directly from the network log.
chrome://net-export/
There you may see a similar windows to this, just press the Start Logging to Disk button and that's it:
Create a batch file using below command and save it as ChromeDebug.bat in your desktop.
start chrome --enable-logging --v=1
Close all other Chrome tabs and windows.
Double click ChromeDebug.bat file which will open Chrome and a command prompt with Chrome icon in taskbar.
All the web application logs will be stored in below path.
Run the below path in Run command to open chrome log file
%LocalAppData%\Google\Chrome\User Data\chrome_debug.log

Interpret/Render output from puts() as HTML

When I run my ruby script, I want the output to be rendered as HTML, preferably with a browser (e.g. Chrome). However, I would very much prefer if I didn't have to start a webservice, because I'm not making a website. I've tried sinatra, and the problem with it, is that I have to restart the server every time I do changes to my code, plus it features requests (like GET/POST-arguments) which I don't really need.
I simply prefer the output from my Ruby program to appear as HTML as opposed to console-text -- since html allows for more creative/expressive output. Is there a good/simple/effective way to do this? (I'm using notepad++ to edit my code, so if its possible to combine the above with it somehow, that would be awesome).
Thanks alot :)
Using the gem shotgun you can run a Sinatra app that automatically reloads changes without restarting the server.
Alternatively, using a library like awesome_print which has HTML formatting, you could write a function which takes the output and saves it to a file. Then open the file in Chrome.
If you don't want to have to manually refresh the page in Chrome, you could take a look at guard-livereload (https://github.com/guard/guard-livereload) which will monitor a given file using the guard gem and reload Chrome. Ryan Bates has a screenshot on guard here, http://railscasts.com/episodes/264-guard.
Here's a function that overrides Kernel#puts to print the string to STDOUT and write the HTML formatted version of it to output.html.
require 'awesome_print'
module Kernel
alias :old_puts :puts
def puts(string)
old_puts string
File.open("output.html", "w") do |file|
file.puts string.ai(:html => true)
end
end
end
puts "test"

Modifying a program to fake a button press

I have an MFC application that I was given (without source code) which opens a window with an 'Update' button, which then performs a very long update after being clicked.
I'd like to modify the program so that when the window is created (or somewhere else such as DoModal), a message is sent to the program to make it think that the button was pressed.
I've been toying around with this for a while in Ida Pro and OllyDbg to no avail. I looked at possibly using PumpMessage, but this did not bring any success.
Any advice?
If you don't like the idea of using a secondary "macro" program, you could patch the original program's binary to call the button's BM_CLICK handler. If you can find some space for the call (minimum 5 bytes without arguments), you can do this with OllyDbg alone (after editing the code, select it, and select "Copy to executable" -> "Selection" from the right-click menu). Otherwise, you'll need to create a new code section with a PE editor (e.g. LordPE or PE Tools) and add your code there (typically you'll want to change a call in the program to a jump to your section, where you perform the original call plus the call to the button's click handler, then jump back to the old position after your patched jump).
There are a few ways to do it using test automation techniques, but the simplest is to simply get the window handle for the button you want and send it a BM_CLICK message. This assumes that you have a working knowledge of C/C++ on Windows. If not, there are other means using .NET or other technologies. I'm not familiar with ida-pro or ollydbg.
See this perl module win32::guitest it could help you to do this.you can write with it a perl script and embed it in your program. or you can use the win32 api that wrap your required needs and use it.
Just create a 2nd program that will lunch it and will send a mouse click using SendInput(...)