Trouble getting Python Appium-Android test to work (connection error) - python

I am trying to run a Python Appium test. I have all the correct things installed on my Ubuntu machine (Android Studio, Appium, drivers, etc).
When I run the Python script (after starting Appium), I get this error:
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Failed to connect 30 times. Aborting.
Stacktrace:
UnknownError: An unknown server-side error occurred while processing
the command. Original error: Failed to connect 30 times. Aborting.
at getResponseForW3CError (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:804:9)
at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:380:37)
This is my code:
example.py:
import os
from appium.webdriver import Remote
from appium_flutter_finder.flutter_finder import FlutterElement, FlutterFinder
# Example
driver = Remote('http://127.0.0.1:4723/wd/hub', dict(
platformName='android',
automationName='flutter',
platformVersion='11',
deviceName='emulator-5554',
app='/home/ironmantis7x/AndroidStudioProjects/demoflutter_1/build/app/outputs/flutter-apk/app-debug.apk'
))
finder = FlutterFinder()
text_finder = finder.by_text('You have pushed the button this many times:')
text_element = FlutterElement(driver, text_finder)
print(text_element.text)
key_finder = finder.by_value_key("next_route_key")
goto_next_route_element = FlutterElement(driver, key_finder)
print(goto_next_route_element.text)
goto_next_route_element.click()
back_finder = finder.page_back()
back_element = FlutterElement(driver, back_finder)
back_element.click()
tooltip_finder = finder.by_tooltip("Increment")
driver.execute_script('flutter:waitFor', tooltip_finder, 100)
floating_button_element = FlutterElement(driver, tooltip_finder)
floating_button_element.click()
counter_finder = finder.by_value_key("counter")
counter_element = FlutterElement(driver, counter_finder)
print(counter_element.text)
I am not sure why the session is not connecting. I see the app in the emulator open up.

Related

app = Application().start("machine.exe") returns error: (0, 'WaitForInputIdle', 'No error message is available')

I am trying to automate a windows GUI machine.exe using pywinauto. I used the command app = Application().start("machine.exe") which throws this error after opening the machine.exe GUI
error: (0, 'WaitForInputIdle', 'No error message is available') in line 901 of application.py. I would like to understand the cause of the error message
I have tried to start the Gui using os.startfile and then connect to the gui using connect ()method
I am using python 2.6.6, OS is windows 7
from pywinauto.application import Application
def test():
app = Application().start("machine.exe")
app.connect(title="machine.exe")
I expected it to just open the gui without any issues.

pyinstaller Error starting service: The service did not respond to the start or control request in a timely fashion

I have been searching since a couple of days for a solution without success.
We have a windows service build to copy some files from one location to another one.
So I build the code shown below with Python 3.7.
The full coding can be found on Github.
When I run the service using python all is working fine, I can install the service and also start the service.
This using commands:
Install the service:
python jis53_backup.py install
Run the service:
python jis53_backup.py start
When I now compile this code using pyinstaller with command:
pyinstaller -F --hidden-import=win32timezone jis53_backup.py
After the exe is created, I can install the service but when trying to start the service I get the error:
Error starting service: The service did not respond to the start or
control request in a timely fashion
I have gone through multiple posts on Stackoverflow and on Google related to this error however, without success. I don't have the option to install the python 3.7 programs on the PC's that would need to run this service. That's why we are trying to get a .exe build.
I have made sure to have the path updated according to the information that I found in the different questions.
Image of path definitions:
I also copied the pywintypes37.dll file.
From -> Python37\Lib\site-packages\pywin32_system32
To -> Python37\Lib\site-packages\win32
Does anyone have any other suggestions on how to get this working?
'''
Windows service to copy a file from one location to another
at a certain interval.
'''
import sys
import time
from distutils.dir_util import copy_tree
import servicemanager
import win32serviceutil
import win32service
from HelperModules.CheckFileExistance import check_folder_exists, create_folder
from HelperModules.ReadConfig import (check_config_file_exists,
create_config_file, read_config_file)
from ServiceBaseClass.SMWinService import SMWinservice
sys.path += ['filecopy_service/ServiceBaseClass',
'filecopy_service/HelperModules']
class Jis53Backup(SMWinservice):
_svc_name_ = "Jis53Backup"
_svc_display_name_ = "JIS53 backup copy"
_svc_description_ = "Service to copy files from server to local drive"
def start(self):
self.conf = read_config_file()
if not check_folder_exists(self.conf['dest']):
create_folder(self.conf['dest'])
self.isrunning = True
def stop(self):
self.isrunning = False
def main(self):
self.ReportServiceStatus(win32service.SERVICE_RUNNING)
while self.isrunning:
# Copy the files from the server to a local folder
# TODO: build function to trigger only when a file is changed.
copy_tree(self.conf['origin'], self.conf['dest'], update=1)
time.sleep(30)
if __name__ == '__main__':
if sys.argv[1] == 'install':
if not check_config_file_exists():
create_config_file()
if len(sys.argv) == 1:
servicemanager.Initialize()
servicemanager.PrepareToHostSingle(Jis53Backup)
servicemanager.StartServiceCtrlDispatcher()
else:
win32serviceutil.HandleCommandLine(Jis53Backup)
I was also facing this issue after compiling using pyinstaller. For me, the issue was that I was using the paths to configs and logs file in dynamic way, for ex:
curr_path = os.path.dirname(os.path.abspath(__file__))
configs_path = os.path.join(curr_path, 'configs', 'app_config.json')
opc_configs_path = os.path.join(curr_path, 'configs', 'opc.json')
log_file_path = os.path.join(curr_path, 'logs', 'application.log')
This was working fine when I was starting the service using python service.py install/start. But after compiling it using pyinstaller, it always gave me error of not starting in timely fashion.
To resolve this, I made all the dynamic paths to static, for ex:
configs_path = 'C:\\Program Files (x86)\\ScantechOPC\\configs\\app_config.json'
opc_configs_path = 'C:\\Program Files (x86)\\ScantechOPC\\configs\\opc.json'
debug_file = 'C:\\Program Files (x86)\\ScantechOPC\\logs\\application.log'
After compiling via pyinstaller, it is now working fine without any error. Looks like when we do dynamic path, it doesn't get the actual path to files and thus it gives error.
Hope this solves your problem too. Thanks

python crashes when running jaydebeapi

I try to connect to a JDBC:hive client via knox and if I run the following code:
import jaydebeapi;
import jpype;
conn = jaydebeapi.connect("org.apache.hive.jdbc.HiveDriver","<hive_jdbc_url>",["<username>", "<password>"],"/path/to/hive-jdbc-uber-<version>.jar")
curs = conn.cursor();
curs.execute("SELECT * FROM Database WHERE day = 20181114 Limit 10");
curs.fetchall();
curs.close();
Python.exe stops working, and if I run the code in pycharm, I get the following error:
Process finished with exit code -1073741819 (0xC0000005)
I think it could be a problem with the environment variable, but I don't know what to chance to fix this issue.

python - java.lang.Exception: Class oracle.jdbc.driver.OracleDriver not found

Being a newbie to python, trying to write a python code to connect to the oracle database without using any Instant client. i'm using jaydebeapi and jpype as suggested in some other threads in this forum. After lot of hurdles, i now got stuck at this error. here is the code.
import jaydebeapi
import jpype
try:
con = jaydebeapi.connect('oracle.jdbc.driver.OracleDriver', ['windb19.ams.com', 'AA3112D1OS', 'advantage', 'C:\Tools\ojdbc8.jar'])
cur = con.cursor()
cur.execute('select * from r_sc_user_info')
except Exception as e:
print e
and the error i'm receiving is as below
C:\Python27\python.exe C:/Project/Robot_Framework/SampleProject/CustomLibraries/DBLibrary.py
java.lang.Exception: Class oracle.jdbc.driver.OracleDriver not found
Process finished with exit code 0
As I couldn't modify anything in the Environment variables, as per the policy, I had to modify the code as below to make it work. I had to keep the ojdbc8.jar in the same path as that of this python file and add following lines of code.
jar=os.getcwd()+'\ojdbc8.jar'
args = '-Djava.class.path=%s' % jar
jvm_path = jpype.getDefaultJVMPath()
jpype.startJVM(jvm_path, args)
try:
con = jaydebeapi.connect("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:#HOSTNAME",["USERID", "PASSWORD"], jar)

Automating hybrid app (android) with appium using python

I am writing automation testing for my hybrid android app created with ionic framework. But during running testing I am unable to start app using its activity. Here is error
selenium.common.exceptions.WebDriverException: Message: An unknown
server-side error occurred while processing the command. Original
error: Error occured while starting App. Original error: Activity used
to start app doesn't exist or cannot be launched! Make sure it exists
and is a launchable activity
Here is my desired capabilities code ........
class TestLoginLogout(unittest.TestCase):
#classmethod
def setUpClass(self):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '7.0'
desired_caps['deviceName'] = 'ZY223XQMWZ'
desired_caps['app'] = PATH('/home/martial/DYFO/dyfo.apk')
desired_caps['appPackage'] = 'dyfolabs.automatioo'
desired_caps['appActivity'] = "dyfolabs.automation.MainActivity"
desired_caps['context'] = 'WEBVIEW'
desired_caps['noReset'] = 'true'
desired_caps['fullReset'] = 'false'
self.driver = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)
Please help me I am stuck here. Thanks in advance..
Download selenium for python from here: https://www.seleniumhq.org/download/
and appium for python from here: http://appium.io/downloads.html
Include these into your project and try again

Categories

Resources