Karate Robot: Not able to click button using image - karate

I am using Karate robot for clicking a button using image.
Below is my code:
robot { app: '^Chrome', highlight: true }
robot.input('OracleDriver')
delay(2000)
robot.click('delete.png')
Sometimes I am able to click delete button for delete.png but other times I am not.
So facing this issue intermittently.

Yes, finding by image is indeed not very reliable and should be only used as a backup when normal windows locators don't work.
I have only the following suggestions:
find a windows locator that works. note that you can navigate from a known locator using someElement.parent.firstChild etc: https://github.com/intuit/karate/tree/master/karate-robot#element-api
try to standardize the resolution that works best
see if using OCR works better
contribute code to Karate to make this better
look for another solution

I tried clicking delete button by using it's class and it is very reliable, below is my code
waitFor('.icons8-delete-blue').click()
I also followed #Peter's suggestion (someElement.parent.firstChild) and it worked for me!, below is the code
waitFor('.modal-footer').children[0].click()
Thanks #Peter for the suggestion

Related

scroll until the element is in view using Selenium2Library Keyword

I am using Robot Framework for my web application automation execution.I had found one such solution using Selenium Web-driver.
scroll until the element is in view using Selenium Webdriver
But I wanted to accomplish this using Robotframewrok-Selenium2Library.
Please suggest such keyword if any.
Thanks.
Finally I got the solution to my query. I have to download the ExtendedSelenium2Library from : Github_Page
then I installed it and it is working fine now.
Thanks.
ExtendedSelenium2Library solved the problem of scrolling down and selecting an element. I used the keyword 'Scroll Element Into View' for my application. However the ExtendedSelenium2Library will not work with the higher versions of the selenium2library.
Below is my 'pip freeze' command output which is working
robotframework==3.0.2
robotframework-extendedselenium2library==0.9.1
robotframework-selenium2library==1.8.0
robotframework-seleniumlibrary==2.9.2
selenium==3.8.0
urllib3==1.22
I was stuck at similar blockade and i could resolve as below:
Hope this might be of little help!
Use ExtendedSelenium2Library Library...
Example:
***Settings***
Library ExtendedSelenium2Library
*** Keywords ****
Add Your Methods
#Execute Javascript window.scrollTo(0,200);
Scroll Element Into View ${YourElement}
Wait Until Element is visible ${YourElement} timeout=5s
Set Focus To Element ${YourElement}
Click Element ${YourElement}

geb jquery.mouseover() not working

The geb documentation shows that it has built in jQuery support. Im interested in one particular method called mouseover. However when I try to use the mouseover function I get a warning saying, "Cannot resolve symbol 'mouseover'". This happens even when I'm using the code in their example. What am I missing?
This might not directly answer your question. But if you are trying to mimic mouse over action in Geb, you could also use
interact {
moveToElement(element)
}
http://www.gebish.org/manual/current/#interact-closures

Is automated testing of Open Layers possible?

I am attempting to use selenium to test OpenLayers-2.13.1 functionality.
I am having problems with mouse clicks, mouse downs etc....
I found a couple of out-dated posts with similar problems but their resolution didn't help me.
Does anyone know of any software that can be automated to properly test Open Layers.
http://lists.osgeo.org/pipermail/openlayers-users/2012-November/026791.html
We have had some success in using Selenium WebdriverIO in running automated tests of our mapping.
The way we address map click throughs is by exposing a function from the map script from which we can get the pixel location of a feature on the map.
function pixelOfFeature (id) {
return map.getPixelFromCoordinate(...coordinate of feature...)
}
Then in our test script, once on our loaded mapping page, we query the map object for the pixel of the feature we want to click, and using webdriverio we can then move the mouse to the pixel value within the map css selector, and then perform a .buttonPress().
var client = webdriverio.remote(options)
client.moveToObject('.map', pixel[0], pixel[1]).then(function(){
client.buttonPress(0).then(callback)
})
http://webdriver.io/api/action/moveToObject.html
http://webdriver.io/api/protocol/buttonPress.html
We use ol3 however the same approach could be taken for openlayers 2
It's probably too late for the OP but hopefully this might help someone get started.

How to change the size of the browser window when running the FirefoxWebDriverProvider in JBehave Web

We're using JBehave Web to drive our selenium test suite for a new project and really like the Etsy.com example available on JBehave, especially the Java/Spring maven archetype as this fits in with our architecture.
The biggest problem so far has been documentation, which is why I'm posting here in the hopes that I can get some help from others in a similar situation.
It looks like JBehave Web only provides a "FirefoxWebDriverProvider" class and no corresponding one for Chrome. Has anyone else run into this problem? Have you written your own ChromeDriverProvider?
Also, we need to change the size of the browser that comes up by default and I can't seem to find a way of doing that during the bootstrapping of the test run.
We're using the Maven archetype: jbehave-web-selenium-java-spring-archetype which uses the jbehave-maven-plugin and the "run-stories-with-annotated-embedder" goal so we're using the "Annotated" method of extending the InjectableEmbedder.
If anyone can provide some guidance, I'd really appreciate it, even if just pointers to more examples.
How To Resize Window
webDriverProvider.get().manage().window().setSize(new Dimension(width, height));
You can easily find code like this by navigating through the code. If you are using Eclipse, Open Declaration and Quick Type Hierarchy options are everything you need.
How to Use Chrome Driver
You can use TypeWebDriverProvider or PropertyWebDriverProvider. For instance:
new TypeWebDriverProvider(ChromeDriver.class);
This should work:
driver.manage().window().setSize(new Dimension(800, 621));
What jokka said is correct, justr a side note: Before resizing window, I always put it to top left corner, so I know that WebDriver can "see" everything:
driver.get().manage().window().setPosition(new Point(0, 0));
Obviously, the driver above is assumed healthy instance of WebDriverProvider
We ended up finding this Chrome Driver and it's been working great. It can take a parameter when it is bootstrapped to start in maximized mode and also exposes the capability to add extensions when it starts up.
driver.Manage().Window.Size = new Size(x, y);
This works fine for me. The x and y are in a feature file.
Try this:
This is working fine for me.
Capybara.current_session.driver.browser.manage.window.resize_to(1800, 1000)

Is there a way to make actions optional in Selenium IDE?

This is a bit of a newbie question, but... is there a way to make actions optional in Selenium IDE? I'll provide a use case.
In the app I'm testing, users see a "hey, you're agreeing to the ToS by logging on"-type modal window at the beginning of each session. They have to click OK to continue, and they don't see the window again until the next session.
Based on what I've seen so far, I need to have one test suite for the first test each day, and a second test suite for all the others. The second suite is exactly the same except that it doesn't have the "click okay to dismiss the initial modal window" step. Alternatively, I could just remember that my first run of the test each day will fail, and that I have to run the test again.
Both of those "solutions" seem unnecessarily awkward. Can I just make the click command optional?
Create a javascript file called user-extensions.js with the below code. Then go into the Selenium IDE Options dialog and select your user-extensions.js file, restart Selenium and you'll be able to choose TryClick which will work the same as Click but suppress any errors.
Selenium.prototype.doTryClick = function(locator) {
try {
return Selenium.prototype.doClick.call(this,locator);
} catch(err) { return null; }
};
Perhaps overdue, but for future searchers.
You could use the if and endIf statements within the IDE.
If you are using cookies to decide whether to hide the ToS dialog, you could check that a certain cookie is set and if so, skip the click.
I haven't used the selenium IDE much, but I think doing the check would be much easier if you are using a programming language. I am not sure how to do it in HTML tests.
If you are using HTML, you could have a look for Selenium IDE Flow Control and see if that can do what you need. I haven't used this myself, but if looks like it supports if statements. You could use verifyCookie to check if the cookie exists.
Hope that helps.
As aj.esler pointed it out Selenium ID Flow control is a good solution that has worked for me.
Here is the Firefox add on
I use the gotoif, here is an example about how you can use it. When skip value is 1 then it will go to the label=jump line and will not execute everything from gotoif like to label=jump .
Another extremely useful flow control add-on for the IDE is SelBlocks
It will give you the ability to use: if/else/for/foreach/while and even a way to read variables from an XML file.
Use http://wiki.openqa.org/display/SEL/flowControl addon.
Make something like this :
1.storeElementPresent | //button[#name="cookie_law_accept"] | cookie_law
2.goToIf | storedVars['cookie_law']!=true | end
3.click | //button[#name="cookie_law_accept"]
4.label | end
Explain:
1.If element is present it will be stored as a "cookie_law" with value "true"
2.If cookie_law is not "true" - go to label "end" - other way go to next step
3.Click to cookie accept button (only when itsenter code herepresent because it its not - you go to "end" label and you skip this command)
4.You go here if there is no cookie law button :)