Use of locators in Katalon mobile automation - testing

I am using Katalon for mobile automation and my question is can I use locators like XPath or CSS directly like we do in Appium or are we restricted to using the findobject locator?

You can add the test object with any properties and then use the Mobile.* keywords. Like this
TestObject myObject = new TestObject().addProperty('xpath', ConditionType.EQUALS, '//xpath-path')
Mobile.tap(myobject, 1)
You will need to import TestObject and ConditionType classes. You can just press Ctrl+Shift+O in script mode and Katalon will do the rest.
Or, add the following at the beginning of the test script:
com.kms.katalon.core.testobject.ConditionType as ConditionType
com.kms.katalon.core.testobject.TestObject as TestObject

Related

How to perform mouse right click in Robot Framework?

I' writing automated tests using selenium in RIDE. I need somehow to right click element on page and click option from context menu.
Is somewhere any library for Robot Framework which may be helpful to do that?
If not, Could you help me how to do that in other way, using existing keywords for example?
I found the solution. I wrote an extension to the Selenium2Library:
from robot.api.deco import keyword
from selenium import webdriver
from selenium.webdriver import ActionChains
from Selenium2Library import Selenium2Library
class ExtendedSeleniumLibrary(Selenium2Library):
#keyword("Right Click Element")
def Right_Click(self, xpath):
driver = self._current_browser()
actionChains = ActionChains(driver)
element=driver.find_element_by_xpath(str(xpath))
actionChains.context_click(element).perform()
Now, I'm not using Selenium2Library but my ExtendedSeleniumLibrary with new method in class and it works.
Open Context Menu keyword from SeleniumLibrary.
Robot tec:
WebElement SighnPad = (appium.findElement(By.id(Lib.getProperty(CONFIG_PATH, "Sighnparent"))). //parent
findElement(By.className(Lib.getProperty(CONFIG_PATH, "sighnchild")))); //child
SighnPad.click();
Robot rightclick = new Robot();
rightclick.delay(1500);
rightclick.mousePress(InputEvent.BUTTON1_DOWN_MASK);
rightclick.mouseMove(630, 420);
rightclick.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

By is not a function in selenium nightwatch

I could not use the default By commands in selenium. Below is my script
driver.findElement(By.xpath("//*[#id='lotstatus_q']/div/table/tbody/tr"));
my script is failing and the result is this:By is not a function
is there any other items that I need to install?
All other By commands are not functioning.
I think you made a mistake, you cannot directly access to Selenium API from Nightwatch.js !
Nightwatch is just an override of the WebDriver Wire Protocole (exposed by Selenium as REST API)
https://code.google.com/p/selenium/wiki/JsonWireProtocol
But you can use XPath selectors with Nightwatch:
client.useXpath().waitForElementVisible("//*[#id='lotstatus_q']/div/table/tbody/tr")
Read the doc about XPath: http://nightwatchjs.org/guide#using-xpath-selectors
You cannot apply the regular Java patterns with NightWatchJS and also NightWatch Apis does not work that way...
Please see the API docs on how you can use http://nightwatchjs.org/api#commands
I think you are trying to do
browser.elements("css locator" , "value of your css", function (result){
// here result is the return from calling selenium wire protocol /elements
// Using the identifier of your CSS locators
})

Access new window elements through selenium RC

I am new to Selenium. This is my first attempt. And I want to access the Elements in the new window through Selenium RC. I have a page with a hyper link clicking on it will open new page. I want to enter username and password elements in the new window. Html Code is
Employee Login
and the new page elements are "emailAddress" and "password" for login.
My selenium code is
public static void main(String args[]) throws Exception
{
RemoteControlConfiguration rc=new RemoteControlConfiguration();
rc.setPort(2343);
SeleniumServer se= new SeleniumServer(rc);
Selenium sel=new DefaultSelenium("localhost",2343,"*firefox","http://neo.local/");
se.start();
sel.start();
sel.open("/");
sel.windowMaximize();
//sel.wait(1000);
sel.click("empLogin");
//sel.wait(2000);
//sel.openWindow("http://myneo.neo.local/user/login", "NewNeo");
//sel.waitForPopUp("NewNeo", "1000");
//sel.selectWindow("id=NewNeo");
Thread.sleep(20000);
sel.type("emailAddress", "kiranxxxxx#xxxxxx.com");
sel.type("password", "xxxxxxxx");
}
First I tried with normal approach, where it failed to identify the elements. Then I tried with open window and selectWindow options, where it through errors like
"Exception in thread "main" com.thoughtworks.selenium.SeleniumException: ERROR: Window locator not recognized: id
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:109)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:103)
at com.thoughtworks.selenium.DefaultSelenium.selectWindow(DefaultSelenium.java:377)
at Demo.main(Demo.java:24)"
Some one told me that it is not possible with Selenium RC. It can achieved through Selenium Webdriver only. Is it true?
Please Help,
Thanks in Advance.
Selenium RC is not maintained anymore, I would recommend you to use WebDriver instead. Selenium RC is a Javascript application where as WebDriver uses browsers Native API. Therefore browser interactions using WebDriver are close to what the real user does. Also WebDriver's API is more intuitive and easy to use in my opinion. I don't see HTML in your question, but you could do start with something like this,
WebDriver driver = new FirefoxDriver();
WebElement login = driver.findElement(By.id("empLogin"));
login.click();
I will say, do as #nilesh stated. Use Selenium WebDriver.
Answer to your specific problem though:
You are failing at this line because you are not specifying a selector strategy.
sel.click("empLogin");
If the id attribute is empLogin then do
sel.click("id=empLogin");
There are other selector strategies you can use:
css=
id=
xpath=
link=
etc...
You can see the full list here.
You will also fail here due to the same issue:
sel.type("emailAddress", "kiranxxxxx#xxxxxx.com");
sel.type("password", "xxxxxxxx");
Put a selector strategy prefix before those fields.
sel.type("name=emailAddress", "kiranxxxxx#xxxxxx.com");
sel.type("name=password", "xxxxxxxx");

Selenium sendText

I need to preface this with "I am a noob".
In WatiN I was able to use sendText("text"); which would send the whole text rather than typing it out one character at a time which is what sendKeys() does. I have looked quite a bit for a sendText() option in Selenium and cannot seem to find anything which works.
Is there a sendText() option for selenium, if so could you provide a code example?
In Selenium RC (the older JavaScript-fueled Selenium that is no longer actively developed), there is the type() method.
In WebDriver (also known as Selenium 2), there's no such thing. However, you can easily emulate it via JavaScript:
// only if your driver supports JavaScript
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement elem = driver.findElement(By.whatever("something"));
js.executeScript("arguments[0].value = 'some text'", elem);

Using Selenium IDE, how to test CSS style information

I am testing a plugin which makes changes to the CSS of HTML elements – how can I use Selenium commands to verify/test these CSS changes?
You can use CSS classes and then check if the element has a specific class.
In Selenium IDE :
Command: assertAttribute
Target: document.getElementById('header')[0]#class
Value: myHeader
Unfortunately Selenium IDE is mis-sold as a Record and Replay tool. Selenium IDE is actually a record, tweak and replay tool.
The tweak part is because the IDE can't record everything that you want. I recommend that you create your test from scratch by hand to get it to check the elements CSS.