I'm using Sikuli IDE. I'd like to know what the command to take a screenshot is, so I can capture the screen at the end of a test.
Something like this
try :
if bla bla bla:
print("blablabla")
else:
TAKESCREENSHOT() #------------------> What command do I put here?
print("TEST_FAILED")
The function is capture, as in
screen = Screen()
file = screen.capture(screen.getBounds())
print("Saved screen as "+file)
It takes a screen-shot, saves it in a file, and gives you the path to that file back.
See the Sikuli documentation on it for full details.
Cheap Sikuli trick for screencaps is to have a defined region, then capture the region.
So if you've got a Chrome browser you want to cap, just set it up something like this:
App.focus('Chrome.app')
ChromeWindow = App('Chrome.app').window()
That will both focus the computer to the target application, and define a region composed of the window parameters of the application. Then run this:
capture(ChromeWindow)
Then use shutil (import shutil) to move the file around to wherever you need it in your local directories. I usually put that code pile into a function I can call when needed TakePicture(Name) where Name is what I want to call the screencap when called in a particular test. Sikuli is both powerful and easy!
To make a screenshot of the window that has focus you simple can use:
focusWindow = App.focusedWindow()
regionImage = capture(focusWindow)
shutil.move(regionImage, os.path.join(r'C:\Screenshots', 'Dummy1.png'))
Related
Can anyone give an advice how to implement using Sikuli analog of Selenium chain element search like driver.findElement().findElement();
first step: finding area
second step find element in this area
Victor Iurkov,
1. You should create a Region and assign to a variable (use Region button from Sikuli IDE panel)
2. Use the variable and apply find() method
It should look like:
yourRegion = Region(2157,169,1049,148)
yourRegion.find("desired-ui-element.png").highlight(2)
Note: Region(2157,169,1049,148) can be created manualy or via Region button in Sikuli IDE
I am new to the Sikuli API and I am using the Sikuli-java-jar file. I want to successfully click on a desktop element using the screen and pattern classes.
So I was trying to create an automation script to install software.
I am able to successfully launch the installer but not able to click on the Next Button present in the pop-up window.
I am not getting any error, it is just that clicking on the image fails.
appInstaller("E:\\Sikulimages\\tc.png");
appInstallers("E:\\Sikulimages\\next.png");
public static void appInstaller(String path) throws FindFailed{
s=new Screen();
img=new Pattern(path);
s.exists(path);
s.wait(img,2000);
s.doubleClick(img);
}
public static void appInstallers(String path) throws FindFailed, InterruptedException{
s=new Screen();
img=new Pattern(path);
s.click(img);
}
I think that the reason is that default Similarity (0.7) is insufficient for small buttons and text.
Sikuli has public class Settings ,
which hosts public static double MinSimilarity = 0.7;
That value is good enough for most image recognition, but it fails for small texts. To get small text clicked, you need to raise similarity for particular pattern, or, like I do, make Settings.MinSimilarity = 0.9;
Sometimes even 0.9 is not enough to recognize small text, well, then try 0.95 , it is usually what helps to pinpoint even smallest texts.
In addition to RPWheeler's answer, if there is something right next to your target image that will appear the same way every time, you can also take a bigger screen clip and then tell Sikuli which part of that bigger image to click on.
For example: if your "Next" button is part of a row of buttons, take the screen clip to include the whole row. Then, in the IDE, double click on the image, and go to the "Target Offset" tab. Here, you'll see an example of your image, and and you click on the part of the image you want Sikuli to click on. -- the default is always the center of the rectangle, but you can change it with the target offset.
You can accomplish the same thing in code like this
t = find(yourImage).targetOffset(dx,dy)
click(t)
where dx and dy are a positive or negative number of pixels away from the center point of the rectangle.
For installing application you need admin rights. So For running any task that require admin rights you need to run sikuli in admin mode. So right click on runSikulixcmd.bat and select Run as administrator for launching the Sikuli and then run the test.
If you are running the test from command prompt run it in admin command prompt.
I was working with Sikuli for desktop application like notepad,
but want to know like can I open new tab in browser using Sikuli?
Yes, using Sikuli you can also automate browser. Take images of required web elements (Open new tab button in your case) and stimulate click action using Sikuli APIs.
Yes, you can use Sikuli for web testing.
In this code example, you can use sikuli app to: open browser --> New tab --> Give a like on a webpage (UTAD in this case):
click("mozilla_icon.png")
click("nova_aba.png")
click("endereco.png")
paste("www.utad.pt")
type(Key.ENTER)
wait(8)
click("like_btt.png")
wait(5)
Images of sikuli code:
yes you can use sikuli for performing open tab first take the image of new tab control like in case of FF https://drive.google.com/file/d/0B09BIsDTY_AuZFpMWko1U3BFc0E/view?usp=sharing .Save this image on you local machine. But make sure that image which is used for reference is visible on screen.Call the function mentioned below by and give it Absolute path to above mentioned image.
//provide absolute path in img
public void click_Image(String img)
{
s = new DesktopScreenRegion();
target = new ImageTarget(new File(img));
r = s.find(target);
// Create a mouse object
mouse = new DesktopMouse();
// Use the mouse object to click on the center of the target region
mouse.click(r.getCenter());
}
So I'm currently working on a Sublime Text plugin [my firt] that displays pips in the gutter that match colors in lines of css. Similar to what JetBrains does:
I have a bit of a problem though. As far as I can tell when adding a region I can only give the region a scope which the template then themes. Now I could write out a template file that defines every hex code as a scope and a theme to match but that sounds ghastly. Is there a better way to do this? Is it possible to color a region separately from the theme? I'm very new to ST plugins so if there's a crucial piece of the docs I've missed let me know :)
Here's a very stripped down version of my plugin to show how I'm achieving this currently:
import sublime, sublime_plugin
class FooCommand(sublime_plugin.TextCommand):
def run(self, edit):
regions = [s for s in self.view.sel()]
for region in regions:
lines = self.view.split_by_newlines(region)
for index, line in enumerate(lines):
self.view.add_regions("csspip-{0}".format(index), [line], "csspip", "dot",
sublime.HIDDEN | sublime.PERSISTENT)
Make a selection and run view.run_command('foo') from the console to see what it does currently [not much].
So it turns out someone has already done what I was trying to do, and I was searching for the wrong things. It's called Gutter Color.
They're actually calling imagemagick to create a custom icon file for every color sublime sees. Which sounds insane, but is the only way to do it [apparently]. I wont quote the code because context is required, but if you got the following line you can work out what they did to make it work:
https://github.com/ggordan/GutterColor/blob/master/line.py#L88
I have put much time and effort into drawing certain 3d plots and surfaces using a Quartz Composition. Everything looks wonderful in my (Cocoa) application's QCView. However, in order to print, I am taking a snapshot of the QCView to generate an NSImage, and putting that in an NSView for my print options screen. However, lines and colors in the snapshot look horrendously aliased. Is there some other way to either directly print from my QCView, or to bypass/override taking a snapshot so that the NSImage looks as good as what's in my QCView? QCView inherits from NSView, but the built-in print method doesn't seem to work.
Thanks!
The obliteration of antialiasing might have something to do with alpha-transparency. As the lowest layer in your Composition, do you have a Clear patch set to opaque black? (It defaults to transparent black, which might be causing the problem here.)
Thanks smokris, but I found that the way to do this is to take a CGImage snapshot. I thought I'd be able to put this snapshot in an IKImageView, which preserves anti-aliasing, but IKImageView suffers from the same issue QCView, in that when print is called you get nothing in your print window.
So, the method that finally worked is to create pdf data from the CGImage snapshot using a CGPDFContext, load up an NSImageView with an NSImage generated from this pdf data, and when this goes to a print window all anti-aliasing is preserved! Very roundabout, but works like charm!