Automating hybrid app (android) with appium using python - 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

Related

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

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.

COM Error while trying to perform action on SAP application

We are using Python pywin32 com library for scripting SAP GUI application running on Windows.
Things were working until yesterday.
Now, while trying to access the line of code below which performs the maximize(), we are getting
com_error: (-2147417851, 'The server threw an exception.', None, None)
And getting the following error while trying to access any object in the SAP window (the last line in code).
AttributeError: Property '.text' cannot be set.
Can someone help? Let me know if more information is needed.
Below is the code snippet which we use to get a new scripting session, launch SAP and perform actions:
from subprocess import call
import win32com.client
import time
GUIPath = 'C:/Program Files (x86)/SAP/FrontEnd/SAPgui/'
WinTitle = 'SAP'
SID = 'xxxxxx.sap.xxxxx.com'
InstanceNo = 'xx'
shell = win32com.client.Dispatch("WScript.Shell")
cmdString = os.path.join(GUIPath, 'SAPgui.exe') + " " + SID + " " + InstanceNo
call(cmdString)
while not shell.AppActivate(WinTitle):
time.sleep(1)
checkGUIExists = False
while not checkGUIExists:
try:
SAP = win32com.client.GetObject("SAPGUI").GetScriptingEngine
session = SAP.FindById("/app/con[0]/ses[0]") # session
checkGUIExists = True
except:
time.sleep(1)
continue
//The lines failing//
session.findById("wnd[0]").maximize()
session.findById("wnd[0]/tbar[0]/okcd).text = <transaction>

How to run Python test case with Appium?

I've created simple test case using Python (in PyCharm editor) which should click on Join/Login button on iOS app, but it doesn't work. Here is the code:
from appium import webdriver
import unittest
import os
class LoginTests(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['platformName'] = 'iOS'
desired_caps['platformVersion'] = '11.0'
desired_caps['deviceName'] = 'iPhone Simulator' # Run on simulator
desired_caps['bundleId'] = 'com.matchbook.MatchbookApp'
desired_caps['app'] = os.path.abspath('/Users/majdukovic/Library/Developer/Xcode/DerivedData/MatchBook-bgvchkbwrithuaegnjgpoffewdag/Build/Products/Debug-iphonesimulator/MatchBook.app') # Path to .app
self.wd = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)
self.wd.implicitly_wait(60)
loginButton = self.wd.find_element_by_id("JOIN/LOGIN") # Button ID
self.assertTrue(loginButton.is_displayed())
loginButton.click()
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(LoginTests)
unittest.TextTestRunner(verbosity=2).run(suite)
If I run this test case it returns:
"Ran 0 tests in 0.000s
OK"
Appium server is already running and app is opened. In PyCharm Preferences I've selected py.test as default test runner.
Details of my setup:
macOS - HighSierra v10.13
Appium desktop app - v1.2.6
Python - v2.7.10
xCode - v9.0.1
Simulator - iPhone 8, iOS v11.0
How about simple code like:
if __name__ == '__main__':
unittest.main()
I'm still not sure what is the problem, I tried a lot of things, but it won't work from Pycharm , so I've written code in Atom editor and run it from Terminal with command:
"python -m py.test name_of_test.py -s" and it works.
Met the same issue. Found out, that "setUp" name is not reads as "test"case.
try this:
def test_testcase1(self):
Testcases should be named like "test_*testcasename_or_whatever*(self)"
File name should be test*.py , For example:
test1.py
Function name should be test*, For example:
def test_testcase1(self):

How do I include the setup method in python-appium base page?

I am just a beginner when it comes to python or coding in general. I'm trying to setup an automation framework using python-appium and the page object model. My question is, How do I include the setup method into my base page? When I call the method from my test script it says 'driver' is unresolved and throws an exception. I know I am just missing something simple but my google-fu has failed me and now I have posted here.
Here is my setup method:
def setUp(self):
"Setup for the test"
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0.1'
desired_caps['deviceName'] = '05157df532e5e40e'
# Returns abs path relative to this file and not cwd
desired_caps['app'] = os.path.abspath(
os.path.join(os.path.dirname(__file__),
'/Users/tyler/Desktop/Instasize_20172109_3.9.9_118_google.apk'))
desired_caps['appPackage'] = 'com.jsdev.instasize'
desired_caps['appActivity'] = '.activities.MainActivity'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub',
desired_caps)
I want to call this method to all my tests or a variation of it depending on the device being used. Here is how I am trying to call it from my base page:
def driverSetup(self):
driverSetup = DriverBuilderAndroid(driver)
driverSetup.setUp()
All of my import statements are present. Let me know if there is any other info you need. If you could refer to a python appium POM tutorial that would be much appreciated as well. This is my first post on stackoverflow.
I created a separate python file called driverBuilder with my setup shown above. I then import it into each of my test files and call the method like this:
from DriverBuilder import DriverBuilder """<--class from DriverBuilder file"""
def test(self):
driver = DriverBuilder.driver

Cannot run PhantomJS with Flask on Ubuntu VPS

I'm doing a testing unit that requires the tests to be run via web browser. I'm using Ubuntu VPS 14 with LAMP stack installed, mod_wsgi, selenium 2.44 and PhantomJS 1.9. I'm testing with the very simple code first:
from flask import Flask, request
from selenium import webdriver
app = Flask(__name__)
app.debug = True
#app.route("/test")
def test():
url = "http://www.google.com"
driver = webdriver.PhantomJS('./phantomjs')
driver.get(url)
result = driver.page_source
driver.close()
return result
if __name__ == "__main__":
app.run()
The code runs very smoothly on my local Ubuntu, it prints out the google page when I connect to: 127.0.0.1:5000/test . On my Ubuntu VPS, my have my flask already setup and running. Now i use the same code to be the index file (supposed all configs are OK and 'hello world' runs), I have 500 Internal Server Error when connecting to http://xxx.xxx.xxx.xxx/test
Apache log sends out the following error:
... service_args=service_args, log_path=service_log_path File
"/usr/local/lib/python2.7/ddist-packages/selenium/webdriver/phantomjs/service.py",
line 53, in init
self._log = open(log_path, 'w') in > ignored Exception AttributeError: "'Service' object
has no attribute '_log'" in > ignored
I changed the log_path for phatomJS but still have the same problem. However, if I open python console, doing line by line as following:
from selenium import webdriver
br = webdriver.PhantomJS('./phantomjs')
....
I got no error. It took me the whole day to fin the problem but I could't be able to fix it. Any ideas how to solve this problem?
Figure out the problem, current phantomjs and init.py don't have enough permission to manipulate the service.py of ghostdriver. Here is the fix:
Add a new user: "add username", then set "add username sudo"
Login to the new user, make sure every command you run from now on starts with "sudo"
In your flask application where init.py resides, create "ghostdriver.log" and "phantomjs" which is an executable file.
Chmod both of them to 777 : init.py, ghostdriver.log and phantomjs
Set the custom config in init.py for phantomjs:
br = webdriver.PhantomJS(service_log_path='./ghostdriver.log', executable_path='./phantomjs')
That's it, now your selenium + flask + phantomjs is now working correctly.

Categories

Resources