How to find same logos, UI elements using sikulix - sikuli

I am new to sikuli.
I am using it for functional test automation of my java spring standalone application. I am having the same set of images(logos) at multiple locations on the screen. and they are generated dynamically as per the application data. In that case how can I find and click on certain buttons/elements in the UI.
Example: like, share, comment text/image will be there several times in facebook page. in that how to we click on particular buttons out of all.(facebook is just an example) i want the similar solution for my application.

I think what you're asking is- given a case where the same image or UI element is present multiple times on the same page, how can I specify one of these elements in one location versus the same element in another?
The quick and easy way to do this would be to capture a larger picture, like as much of the window as you can, and click the image in parentheses after the click action; this opens a window reading file, matching preview, and target offset. Click target offset, use the mouse wheel to zoom in, and click on the exact point of the picture that you'd like to click.
It's possible to click in multiple places on a captured image, provided you use different click() commands, and you can set the target offset for each click() command without needing a new picture.
With just this one image, you can potentially click every square on the board provided you take the time to set the offset for each of the 64 click() commands it'd take to do so. http://files.chesscomfiles.com/images_users/tiny_mce/cigoL/Chessboard.png
The more difficult solution would be setting up regions, and searching those regions for the matching pictures, but for what you're looking for this should- for more about regions and setting it up check links below. Cheers!
http://sikulix-2014.readthedocs.io/en/latest/index.html

Based on your FB example you could use setROI() to focus on the top post on the page (imagine a rectangle that covers a complete post on the news feed) from there I would loop:
if exists(profile pic):
click(like button)
elif exists(profile pic 2): # If you are testing more than one user
click(like button)
else : type(Key.DOWN) #repeat as needed
Getting the next post into the ROI may be tricky but using WHEEL_DOWN may help if you can adjust your lines traveled with each wheel click on your system.

Related

How do I get the user's input from a .html file to a .c file?

I'm trying to get the input from my html webpage, which has a text box and submit button. How can I get the user's input in a separate .c file, so that I can change what happens in my html file depending on the input?
Here is the problem for my assignment:
If the player input the word NORTH, SOUTH, EAST, or WEST, the program will programmatically generate a webpage that hyperlinks to another room. Do printf() to the browser.
You will need to do something like this:
printf(“< a href=\”http://URL\”>Press HERE to go North< /a>”);
The above printf() will display on the browser a hyperlink. The player will simply click on the word Press HERE to go North with their mouse to cause the browser to change to another webpage. The HTML tag to link to another webpage is:
< a href=”URL”>TEXT TO CLICK< /a>.
You will need to do this for each direction: NORTH, SOUTH, EAST and WEST. If the player input the word GOLD, the program will programmatically generate a webpage that displays the amount of gold pieces the player currently owns and a hyperlink to return the player back to the current room.
Might need a little bit more clarification on what exactly it is you're trying to achieve, but if you do actually want the HTML file to change based on the user's input, depending on whether you want that change to be permanent or based on the individual user, you have a couple of options:
1) If you want the user's input to permanently change the HTML file, have it posted to another server-side page on your website (PHP for example) -- then take the user's input and you can use PHP to write actual changes to the HTML file stored on the server which is delivered to your end users. I would advise being very careful with this and make sure you sanitise the input properly to avoid security issues.
2) Alternatively if you want the user's input to change the page they're viewing in some way in real-time and only for that user, you probably want to make use of JavaScript and set the innerHTML of elements based on the user's input.
If you clarify a little more in the comments for this answer what exactly you're trying to achieve, I can give more specific help.

Selenium state of button to be clicked

I have a site which is populated from a database. I want to access the pages in Selenium. The number pages associated with a particular topic is variable.
Using Selenium I am clicking through successive pages using a line like
driver.find_element_by_xpath("""//*[#id="mainContent"]/
div[2]/div/div[2]/div[1]/
div[3]/div[2]""").click()
This works successfully.
However I would like to detect when the element I am clicking (a next button) is "greyed" out rather than having to predict how many pages are available.
Currently I am using a block of code inside a for loop with a counter for the number of available pages.
EDIT: The page element has the word Inactive added when it is "greyed out" as in
<div class="paginationBtn paginationNextContainer inactive"><div class="icn chevron-left"></div><div class="visuallyHidden">Previous</div></div>
If your button is changing its color on click, it's associated with CSS attribute.
I advise to look at this answer to learn the subject. For your case, I advise you to develop a method to get the button color value before and after, as your script should operate accordingly.

Dynamically changing component reference

This seems simple enough but I can't quite think of how to actually do it...
In IBM Web Content Management (WCM) version 7 I have a Presentation Template (PT) which calls a Menu Component to display some content items.
I also have some (static) links on the sidebar which I want to basically just change the menu component that is being used, and that's it.
So for example...
In the PT:
[Component name="Main Page"]
When I click on a link, I want the exact same PT to be displayed except I want it to use:
[Component name="Next Page"]
Basically, Main Page and Next Page are showing the same content items, they just have different filters on them (so they appear to be different pages). The "Main Page" shows "everything" and then if you click on a link it's suppose to only show a subset of that.
I can't quite figure out how to connect the link to the PT to change it. I've thought about using JavaScript or JSP to simply rewrite the HTML, but even then I'm not sure how I set it up to say that: "if the link has been clicked, rewrite the HTML" because I'm not sure what to even point the link to, or pass through the link.
I thought about creating different content items with different PTs to link to, but there are about a dozen links (and therefore a dozen different Menu Components that I want to use), so I thought it might be better in the long run to just use 1 dynamic PT (in case the number of links grows).
It is only that one component that needs to be changed in order to display how I need for every link though.
Any ideas how to go about doing this?
So this is how I resolved this:
I created a component reference element in the content items called "menuComp" and then I set that to point to the appropriate Menu Component for each particular page.
In the presentation template, I removed the component reference and changed it to an [Element] tag which used key="menuComp".

Using a single shared element across multiple partial views

I have a basic ASP.Net MVC 3 application which has a number of controllers and a number of actions (and subsequently views)
A common feature of the application is to show a pop-up dialog window for basic user input. One of the key features of this dialog process is a faded mask that gets shown behind the dialog box.
Each of these dialog window controls is in a separate Partial View page.
Now, some view pages may use multiple dialog boxes, and therefore include multiple partial views in them - which as is would mean multiple instances of the "mask" element.
What I am trying to find a solution for is to only need to create one instance of a "mask" element regardless of the number of dialog partial views I include, and then the script in each partial dialog will have access to this element (so basically it just needs to be on the page somewhere)
The only real idea I have come up with so far is to add the "mask" element to the master page (or in the original view page) and this will mean it only gets added once. The problem here is that it will be added even when it is not needed (albeit one small single element)
I can live with this, but I would like to know if there is a better way to handle these kinds of scenarios?
A quick idea that came to mind is some kind of master page inheritance hierarchy, So I may have a DialogMasterPage that inherits from the standard current master page. How does that sound for an approach?
Thanks
To do something like this, where each module can register their need for a certain thing in the master page, you can use HttpContext to store a flag of whether you need to write the mask div, and just set that property in each partial. At the end of the master page, if the flag is set, you can then write the mask div if its set to true.
Obviously to make this cleaner you could wrap it all in an HtmlHelper extension or something.
My initial thought is for you to use something like jQuery UI where it handles the masking for you or if you are using something custom you can load the content for the dialog via ajax then show it in the single dialog on the master page.

Classify a program from a screenshot

I need to write and algorithm that can detect which state an application (used to fill out forms) is in based on screenshots.
It has 2 inputs:
A: Approximately 2-10 screenshots from an application with different tabs selected. These are made by the user, so i can instruct him to things like "select the upper area of the program" or "select the whole window", but i can not expect pixel-perfect precision.
B: a screenshot of one of these states. The forms are filled with different data.
The goal is to determine which screenshot from "A" is from the same state as "B".
An example screenshot:
An example based on this screenshot:
A input: 10 screenshots from this program with "Menu","Sale Order","Purchase order",... tabs selected
B input: the screenshot above.
The task is to determine which of the 10 screenshots matches this image.
I have tried to use an image descriptor algorithm, (SURF) but it has a really high error ratio, since its not made for such tasks.
Anyone has an idea how to make such classification? Should i use some filter (e.g median or blur) on the screenshots, and then run trought some classification algorithm? Or extract some other feature to classify (FFT,histogram,..)?
I guess you can use the tab width instead of the tab label, which is much easier to calculate. For example, {"Menu", "Sale Order", "Purchase Order"} all have different widths.
If you have to look inside the tab, you can attempt some template matching.
Detect the text of each tab, then look at the background color.
Alternatively, locate one of the menu icons for pixel-level registration, then do a pointwise sampling to determine which tab is selected.