In Appium Python, how to press key code by key name? - python-appium

I am writing Python Appium code. The code needs to press the HOME button. Right now I have
driver.press_keycode(3)
where 3 is mapped to KEYCODE_HOME according to keycode mapping.
Is there a way that I can refer KEYCODE_HOME in my code so that my code is more readable?
I could have done the following:
adding a comment
# HOME Key is 3
driver.press_keycode(3)
or assigning a variable
home_keycode=3
driver.press_keycode(home_keycode)
But I'd more like to see something like
driver.press_keycode(AppiumKey.HOME)
Does such a thing exist?
Thank you

So you can create Enum class and call variables like Keys.HOME etc
class Keys(Enum):
"""
List of keys
"""
HOME = 3
class PO(Base):
press_key(Keys.HOME)
Or use an existing solution as well python-client nativekey.py
press_key(AndroidKey.HOME)

I use an example to substantiate Dmytro's answer
import appium.webdriver.extensions.android.nativekey as nativekey
androidkey = nativekey.AndroidKey
value = 'TAB' # use TAB key as an example
keycode = androidkey.__dict__.get(value, None)
print(f"key={value}, keycode={keycode}")
# driver init code is skipped
driver.press_keycode(keycode)

Related

Unable to select an option from a drop down in Katalon studio

I am new to Katalon Studio and I am facing an issue regarding selection of the drop down.
Please find below the details:
This is the HTML :
I have tried using selectByIndex with the object xpath as:
//div[#class='paCriteriaContainer']//select[#class = 'pa-criteria-select a-select initialized']
It does not select any option and fails with an error stating "Unable to select option by index '2' of object"
Note:
I tried clicking on the input and then selecting the option, but that doesn't seem to work either.
Selecting by label and value don't work either
Please help me here.
Thank you
Try to capture an object and then use following methods :
WebUI.click(findTestObject(Your captured object))
WebUI.selectOptionByValue(findTestObject(Your captured object), 'TEST (2020)', false)
Did you done as I've described and it does not work ?
I tried clicking on the input and then selecting the option, but that doesn't seem to work either.
Are you sure you are clicking the right element in this case?
Try the following instead: create programmatically the element and select by value (note, value isn't the text contained, it is the value html attribute):
TestObject to = new TestObject().addProperty("xpath", ConditionType.EQUALS, "//div[#class='paCriteriaContainer']//select[#class = 'pa-criteria-select a-select initialized']")
WebUI.selectOptionByValue(to, '40696', false)
You have some options to do that, I reggardly suggest you that use always the xpath to reach all the elements that you want to use. The reasson is because the object reports usually fail and, in my opinion, this way is so much more complicated.
But obviously, the xpath will change if the web do, so take care with it.
The imports you need:
import static org.junit.Assert.*
import org.openqa.selenium.By
import org.openqa.selenium.Keys
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
def driver = DriverFactory.getWebDriver()
//If you want to click your input would be:
WebUI.click(WebUI.convertWebElementToTestObject(driver.findElement(By.xpath("(//input[#id='a-select-paCricteriaId_6908'])"))))
//**you just can click on "TestObject" type, and findElement returns "Element" type**
And if you want to select the option you need to know the whole path (I cannot get it with the given information).
An important tip for testing the xpath is to use this function in console mode (F12):
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
//And this code in the same console to test your xpath:
getElementByXpath("YOURTESTXPATH")
Furthermore, there are other ways to reach the same objetive with xpath, for example:
import com.kms.katalon.core.testobject.TestObject as TestObject
...
TestObject tobj = new TestObject('myTestObject')
String expr = '/some/valid/xpath/expression'
tobj.addProperty('xpath', ConditionType.EQUALS, expr)
WebUI.click(tobj)
You have a lot of information if you google "how to get elements by xpath katalon".
Here you can get official information about it:
https://docs.katalon.com/katalon-studio/tutorials/detect_elements_xpath.html#what-is-xpath
Test in the browser console
$x('//*[contains(#class, "pa-criteria-select a-select initialized")]')
if more than one result appear then you can access it like this
$x('(//*[contains(#class, "pa-criteria-select a-select initialized")])[1]')
then you can also access their children
$x('(//*[contains(#class, "pa-criteria-select a-select initialized")])[1]/option')
Use WebUI.selectOptionByIndex keyword but the object should point to the select tag instead of the div.
Update the object element and your code should work

Python w/QT Creator form - Possible to grab multiple values?

I'm surprised to not find a previous question about this, but I did give an honest try before posting.
I've created a ui with Qt Creator which contains quite a few QtWidgets of type QLineEdit, QTextEdit, and QCheckbox. I've used pyuic5 to convert to a .py file for use in a small python app. I've successfully got the form connected and working, but this is my first time using python with forms.
I'm searching to see if there is a built-in function or object that would allow me to pull the ObjectNames and Values of all widgets contained within the GUI form and store them in a dictionary with associated keys:values, because I need to send off the information for post-processing.
I guess something like this would work manually:
...
dict = []
dict['checkboxName1'] = self.checkboxName1.isChecked()
dict['checkboxName2'] = self.checkboxName2.isChecked()
dict['checkboxName3'] = self.checkboxName3.isChecked()
dict['checkboxName4'] = self.checkboxName4.isChecked()
dict['lineEditName1'] = self.lineEditName1.text()
... and on and on
But is there a way to grab all the objects and loop through them, even if each different type (i.e. checkboxes, lineedits, etc) needs to be done separately?
I hope I've explained that clearly.
Thank you.
Finally got it working. Couldn't find a python specific example anywhere, so through trial and error this worked perfectly. I'm including the entire working code of a .py file that can generate a list of all QCheckBox objectNames on a properly referenced form.
I named my form main_form.ui from within Qt Creator. I then converted it into a .py file with pyuic5
pyuic5 main_form.ui -o main_form.py
This is the contents of a sandbox.py file:
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import main_form
# the name of my Qt Creator .ui form converted to main_form.py with pyuic5
# pyuic5 original_form_name_in_creator.ui -o main_form.py
class MainApp(QtWidgets.QMainWindow, main_form.Ui_MainWindow):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
# Push button object on main_form named btn_test
self.btn_test.clicked.connect(self.runTest)
def runTest(self):
# I believe this creates a List of all QCheckBox objects on entire UI page
c = self.findChildren(QtWidgets.QCheckBox)
# This is just to show how to access objectName property as an example
for box in c:
print(box.objectName())
def main():
app = QtWidgets.QApplication(sys.argv) # A new instance of QApplication
form = MainApp() # We set the form to be our ExampleApp (design)
form.show() # Show the form
app.exec_() # and execute the app
if __name__ == '__main__': # if we're running file directly and not importing it
main() # run the main function
See QObject::findChildren()
In C++ the template argument would allow one to specify which type of widget to retrieve, e.g. to just retrieve the QLineEdit objects, but I don't know if or how that is mapped into Python.
Might need to retrieve all types and then switch handling while iterating over the resulting list.

Which file contains function of core/session in magento?

I need to customize other's code,
so I found they used
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
in Order.php file for custom order email
so I can't find this function getMyCustomBlockInfo();
Can anyone tell me where this function reside?
Thanks
those are magic functions get() and set() and you are asking a session variable there that is set as
Mage::getSingleton('core/session')->setMyCustomBlockInfo();
somewhere in your code. If you use terminal you can easily find by making a following grep:
grep '>setMyCustomBlockInfo(' . -rsni
and it will list the files where your variable is set to session.
example :
Mage::getModel('catalog/product'); //or
Mage::getSingleton('catalog/product');
the code must be in '../app/core/Mage/Catalog/Model/Product.php' file
then
Mage::getSingleton('core/session');
the code must be in '../app/core/Mage/Core/Model/Session.php' file
because the class Mage_Core_Model_Session's parent::parent is Varien_Object, then you can do all magic functions and you can ->getData() to see the Data inside.
Mage::getSingleton('core/session')->getData();
on your problem when go call ->getData() you can see data : [my_custom_block_info]
you can set it with call
Mage::getSingleton('core/session')->setMyCustomBlockInfo('what');
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
// will return 'what'

How do I get a list of members in a Python module, or how should I create plugins?

I'm writing a sort of dashboard-esque program in Python to make tasks that I do frequently here at work a little better/easier.
What I currently have set up is an actions module. actions contains an actionlist that is a list of classes. Each of my classes has a .title, .icon (base-64 encoded string for use with tkinter.PhotoImage), and a .action function.
Using tkinter I create a new button for each of these actions, with the appropriate icon, text, and the command of the button set to the .action. So far it works quite nicely, but if I want to create a new action, I have to go into my actions module, create a new class, and then put that class in my actionlist.
What I would like to do is be able to dynamically generate this actionlist based on what files are present in my module. So I would like to have something like this:
actions/
__init__.py
someaction.py
do_another_thing.py
do_all_the_things.py
chop_down_the_tree_with_a_herring.py
And whenever I would like to create a new action, I just put a .py script in my actions folder and then it would automagically generate the list of actions for me, however I can't seem to find any good way of creating this list. I've thought of using something like os.listdir to get the list of files, but neither that or the other methods of introspection (dir, and inspect.getmembers) seemed to have quite what I wanted. Of course, it's possible that I just missed the features that I need.
In any case, pointers in the right direction would be great. Thanks!
SOLUTION:
Lennart's solution, with some slight adaptations worked for me.
Inside my __init__.py I have the following code:
plugins = []
__all__ = [
'do_all_the_things',
'do_another_thing',
'someaction',
'chop_down_the_tree_with_a_herring',
'seek_the_grail',
]
Then inside each of my plugins I have something like this:
from actions import plugins
class SeekTheGrail:
def __init__(self):
self.text = 'We Seek The Grail'
self.icon = b'R0lGODlhkABJAPcAABsVGH6DWWaElDxIdU1LM8mxc2RnQ3iFaLi8mLmQZqxpOy4rPq28y41NNTMvJIujl5qbakpMTdubSWJoV4KhxOfTnkBYoL+EQ26FgF84LtzZyaRoTFdbPLm/sK+hnHF5WbqGUbmgbeLEglxnbyUdJEBALHFMM6ivg4aRasfMybyQUa+gfVleUKGxnXV4S9Wzf6t6Q5NYRDQwL4+df2GEv2FFPM3EsohoSIFpVNKgao+Lgqp6UNrClT89PVJojk9tp4l7Vy0mJickG45eOZ6nhJ6zwUZYd01MQIehsWdwW8zQ3ZWHZVZgXmxNPZ2SaEgxLrxpPr+6iNbY3dKHTTY9W4OWl7K0mJeFVKe738LHs9aTT8N7TsGbW217bmZBLLmygdbQyEZEPnZdO0cpJsbFyXuSgMnIn5OgjFJTQTxKYOPVsm16ZHBgTohwS5mhmk9utC8cGtiSQ7iocNSobLC0rry9pLOYZ6pvQ7e/vLmGXGpvTEVBNDApNG9UQHmFdN28galfOnaVuGR7ikBYkDxQiuSuXObo5pmy1UZhoYSj1miFqF97n9S+dJ+zr45hRlh4uKyWfMl5O9enfHmXp+Xj0OTPjOjgvDQ0UOKnWNTMs5OUguHMnaOPWYJENJSOlEgzJMFtTHiWyd6ycpBUOKGic2NxbdKFO7S2vGBVTZqmr2RWXM+QZ0lkrbjEyouowbOof2yMvE9fc6JhRNaYZWyIjOHFjLG0pHJ7fOHWvGB6lB8cGuGkTLKomlVvjMFwQJupnJB3TNueV5yapD1PdkRfj2doTJucdGBoZDw+TNm9jFlxfNnZ1FldRIKSdMfN1LqSXMyujHpGPKF8XI6IdJOFXLx+XGVENHiUjMV7RISMXDY1Pjg3JKZwTm1TNIFxVuLf33GMp8a9mYeipH+HfjQdJFBAK6iwjKCff9jFpIV9ZDYkG5uyzGZgXpiSdMyHXMa2lr/HvNKSXLqzjNTR1HJdRHx+hFR2rNSHRG+NmU9UTj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OutA3OwGc5ABWBIghAIh3PwBE1IAlRoAy1hgwloA2bgh6dBl6nAAFZTEBISn9py33xIgggoKGU8gl/wwkMgYP8GcAUYmoRe2IdvTOABGIBL6BPR4Ac9uAEXECwmq93aZYFT0YWpveMS+BZprgxukadKmQA/OIAAoBdvPoBDTuQDIIU6IAJIfp0DuBnj6AMUSQdI0AOtCQAcSIcloIZs8AYXkA+86wEovoZjUMYIEYIwqIobYQF0qbS8SehmeADj6YdAKAIGKAIkEIQRiAV8qFBiMII0poKObt02aAIahDUe2QM+mEcNpo1t+ZYWk0oOxLo9QI41YIYkIIJzIAKaPodEJoLJ/mkr+AUiOADjiBtA4YAjKIBMiI9iUIP0mw+m1hJZokwWuKdWqjcJEZUlmpMIwIBGeM+uAed+eEnU3IcSfZgEAaAFWpgEGiCGBZbGqwoIADs='
def action(self):
print('I am Arthur, King of the Britons!')
plugins.append(SeekTheGrail())
and now I just have to modify the __all__ collection when I want to add or remove the actions from loading.
The way to create plugins is to have a plugin registry, and register plugins there. This can be done from the amazingly simple, like just defining a global list in a module:
plugins = []
And then registering the plugins with:
class APlugin(object):
blahblah
from themodule import plugins
plugin.add(APlugin())
This can be made more flexible by having types of plugins and registering them with a name etc. But then you are on the path to complexity, and then you might want to take a look at the Zope Component Architecture, which simply speaking is a very powerful system for making your application pluggable.
It should be noted that in any case it's best to have a list of what plugins should be activated instead of auto-discovering them. This can be as simple as a list in a text file or a setting in a config file. This enables you to easily activate and disactivate the plugins.
You can use something like this:
actions = {}
for filename in os.listdir('somepath/actions'):
actions[filename] = __import__('actions.'+filename)
for name,class in actions:
createButton(name,class)
Where in the createButton you create your tk_inter button and assign it the functions from the class. The important bit i suppose is that you can use __import__ to import a class using its string name and save it as a variable.

Problem importing ZEXP files programmatically

I'm developing a Plone Product that needs to import objects programmatically previously exported to ZEXP files. It's working perfectly, except the navigation bar. When one object is imported, it does so correctly, but the navication bar is not updated. The object can be accessed through it's URL and it's parent container contents tab.
Bellow is the code I used to import the objects. It's based on zope's ObjectManager._importObjectFromFile implementation.
def importDocument( app, fileName, container ):
app._p_jar.sync()
owner = 1
connection = container._p_jar
ob = connection.importFile( config.REMOTE_DIR + fileName, customImporters={ magic: importXML, } )
id = ob.id
if hasattr(id, 'im_func'): id = id()
try:
container._setObject( id, ob, set_owner = owner, suppress_events=False )
except AttributeError:
print "AttributeError"
# Try to make ownership implicit if possible in the context
# that the object was imported into
ob = container._getOb( id )
ob.manage_changeOwnershipType( explicit = 0 )
transaction.commit()
return True
I've noticed that the _setObject implementation fires an ObjectAddedEvent event in it's code, and it's after that event that the menu gets updated when I use the ZMI interface to import an object, so I figure something is listening to this event and handling the menu, but oddly, it doesn't happen when using my code.
Generally speaking, importing zexp objects is not supported (in part due to cases like this where unexpected or unintended results may occur). If it works, great. If it doesn't, you are "on your own" and probably better off copying the Data.fs file to a new software stack.
That said, I'm not sure I understand why clear and rebuild the catalog (ZMI -> portal_catalog -> tab 'advance' -> 'clear & rebuild') is not the answer here. According to its description its job is to "walk the entire portal looking for content objects which should be indexed in the catalog and index them".
Unless I misunderstand, you've just described a situation where newly imported content "should be indexed" because it hasn't been indexed yet.
If you are worried about the length of time required to clear and rebuild, try running it from the command line with something like this:
http://svn.plone.org/svn/plone/plone.org/Products.PloneOrg/trunk/scripts/catalog_rebuild.py
If you are worried about crawling the whole site, then call indexObject() on each object (http://dev.plone.org/plone/browser/plone.org/Products.PloneOrg/trunk/scripts/catalog_rebuild.py#L109)
Maybe try manually rebuilding the whole catalog after the import is complete? It might give you more hints to what is wrong ...
ZMI -> portal_catalog -> tab 'advance' -> 'clear & rebuild'.
You may need to "publish" the object after import to make it visible.
Use the manage_importObject method instead.