When i run the monkey runner, i am getting swt error - monkeyrunner

I have created the below script and saved it as (test.mr) in the lib folder and running from the command prompt C:\Android_Stuff\android-sdk-windows\tools\lib\monkeyrunner test.mr
#Importing monkeyrunner
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
#waiting for the device connection
device = MonkeyRunner.waitForConnection()
#Installing my app.
device.installPackage('C:/Android_Stuff/android-sdk-windows/tools/lib/purchase.apk')
#starting my demo page
device.startActivity(component='com.mobilemoneynetwork.purchase/.demo')
#selecting the Menu Button.
device.press('KEYCODE_MENU','DOWN_AND_UP')
I am getting
Unable to access jarfile ..\framework\archquery.jar
SWT folder '' does not exist.
Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.

Set ANDROID_SWT path in environment variable it should be "your path"\Android\Sdk\tools\lib\x86_64

Related

requests_html render() throwing OSError: [WinError 14001]

Hello I'm trying to do web scraping with the python module requests-html to handle dynamic content on the page https://www.monster.com/jobs/search?q=Software+Engineer&where=. My code is:
from requests_html import HTMLSession
url = 'https://www.monster.com/jobs/search?q=Software+Engineer&where='
session = HTMLSession()
response = session.get(url)
response.html.render()
but when I run response.html.render() I get this error
OSError: [WinError 14001] The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail
The first time I ran render() I got
[W:pyppeteer.chromium_downloader] start chromium download.
Download may take a few minutes.
[W:pyppeteer.chromium_downloader]
chromium download done.
[W:pyppeteer.chromium_downloader] chromium extracted to: C:\Users\user\AppData\Local\pyppeteer\pyppeteer\local-chromium\588429
however the file path doesn't exist but pyppeteer is actually an installed package (pyppeteer==0.2.5). Does anyone have an idea what is going on?
You're having this issue because chromium setup failed.
You can either try to reinstall request_html or what I did was switching from the python from the Windows store to the download from the python website and then installing request_html again.
After having everything setup correctly with the downloaded python I switched back to python 3.9 from the store and everything is still working.

Robotframework, AutoIt: Error message "No keyword with name 'Send' found"

I'm trying to get familiar with the robotframework using autoitlibrary to test Windows applications. I found some examples which use the Send command to type text into a notpad window.
That's what I've done so far:
*** Settings ***
Library AutoItLibrary
*** Variables ***
${app} C:/Program Files/Notepad++/notepad++.exe
*** Test Cases ***
Enter text
Run ${app}
Win Wait Active new 1 - Notepad++
Send This is just a test.
So, the Notepad++ window is opened, but then it failed with the No keyword with name 'Send' found. message. I suppose there is no Send command in the AutoItLibrary, but I also cannot find any other command which may do this job.
AutoIt is installed, and so is the wrapper by pip install robotframework-autoitlibrary.
There really exists a Send keyword in AutoIt, but supposedly not in the wrapper for robotframework.
And ideas to fix this?
UPDATE: Windows 10 (64bit in a VirtualBox), Python v3.7.6 (32bit), RF v3.1.2, RF-AutoItLibrary v1.2.4, AutoIt v3.3.14.5
The "Search Keywords" dialog in RIDE provides AutoItLibrary as a Source, but then list only a few commands. So I suppose the library is accessible, but incomplete.
import os, re, subprocess, sys
# Set path to Python directories.
programfiles = os.environ['programfiles']
if not programfiles:
exit('Failed to get programfiles')
python_dirs = [os.path.join(programfiles, 'Python35'),
os.path.join(programfiles, 'Python36'),
os.path.join(programfiles, 'Python37'),
os.path.join(programfiles, 'Python38')]
# Process each python directory.
for python_dir in python_dirs:
print('---')
# Set path to AutoItX3.dll.
autoitx_dll = os.path.join(python_dir, r'Lib\site-packages\AutoItLibrary\lib\AutoItX3.dll')
if not os.path.isfile(autoitx_dll):
print('File not found: "' + autoitx_dll + '"')
continue
# Set path to the makepy module.
makepy = os.path.join(python_dir, r'Lib\site-packages\win32com\client\makepy.py')
if not os.path.isfile(makepy):
print('File not found: "' + makepy + '"')
continue
# Generate cache using make.py.
command = [os.path.join(python_dir, 'python.exe'), makepy, autoitx_dll]
with subprocess.Popen(command, stderr=subprocess.PIPE, cwd=python_dir, universal_newlines=True) as p:
stderr = p.communicate()[1]
print(stderr.rstrip())
parameters = re.findall(r'^Generating to .+\\([A-F0-9\-]+)x(\d+)x(\d+)x(\d+)\.py$', stderr, re.M)
if len(parameters) == 1:
parameters = parameters[0]
print('Insert the next line into AutoItLibrary.__init__.py if not exist.\n'
' win32com.client.gencache.EnsureModule("{{{guid}}}", {major}, {minor}, {lcid})'
.format(guid=parameters[0],
major=parameters[1],
minor=parameters[2],
lcid=parameters[3]))
# Pause so the user can view the subprocess output.
input('Press the return key to continue...')
The generated cache done by win32com\client\makepy.py for AutoItLibrary from the setup.py is saved in the %temp%\gen_py folder. This is done only when setup.py is executed. If the %temp% directory is cleaned later, which removes the cache, then I notice keywords like Send may fail to be recognized by the robotframework.
One solution appears to be regenerating the cache. The code above will generate the cache by use of makepy.py. It may also print a message about inserting win32com.client.gencache.EnsureModule(...) into AutoItLibrary\__init__.py for any of the Python versions as needed. This will ensure the cache is available when AutoItLibrary
is imported.
Change paths in the code to suit your environment.
With further research:
AutoItLibrary currently has AutoItX 3.3.6.1 and latest AutoIt has AutoItX 3.3.14.5. Important to know as one version registered can overwrite the registration of the previous registration.
AutoItLibrary currently registers AutoIt3X.dll without the _x64 suffix on the name on x64 systems. I may reference AutoIt3_x64.dll to define difference between x86 and x64.
Any version of AutoIt3X.dll and AutoIt3_x64.dll uses the same ID codes and the last registered wins (based on bitness as both x86 and x64 registrations can co-exist).
The TypeLib class key registered ID is {F8937E53-D444-4E71-9275-35B64210CC3B} and is where win32com may search.
If AutoIt3X.dll and AutoIt3_x64.dll are registered, unregister any 1 of those 2 will remove the AutoItX3.Control class key. Without this key, AutoIt3X will fail as AutoItLibrary needs this key. To fix, register again e.g. regsvr32.exe AutoIt3X.dll as admin in the working directory of AutoIt3X.dll.
The methods of any same version of AutoItX will match i.e. AutoIt3X.dll and AutoIt3X_x64.dll only changes in bitness, not methods.
Inserting win32com.client.gencache.EnsureModule("{F8937E53-D444-4E71-9275-35B64210CC3B}", 0, 1, 0) into AutoItLibrary\__init__.py should ensure the cache is always available for any AutoItX version. The initial code can be used to generate the cache, though the suggested change in AutoItLibrary\__init__.py makes it obsolete as the cache is generated on import of AutoItLibrary. If the ID was not constant, then the initial code may inform you of the ID to use.
The cache is important as it has generated .py files with methods like e.g.:
def Send(self, strSendText=defaultNamedNotOptArg, nMode=0):
'method Send'
# etc...
which if missing, makes Send and many others, an invalid keyword in AutoItLibrary.
If AutoItX 3.3.14.5 is registered, the - leading methods are removed and the + leading methods are added as compared to AutoItX 3.3.6.1:
-BlockInput
-CDTray
-IniDelete
-IniRead
-IniWrite
-RegDeleteKey
-RegDeleteVal
-RegEnumKey
-RegEnumVal
-RegRead
-RegWrite
-RunAsSet
+RunAs
+RunAsWait
So if any of those methods causes error, then you may want AutoItX 3.3.6.1 registered instead. In the AutoItX history, 3.3.10.0 release is when those method changes happened.
Fix:
Check your python architecture ( is it 32 or 64 bit)
For 32:
Open cmd in "Run as administrator" mode
run the command pip install robotframework-autoitlibrary
Now clone the autoit library source code:
https://github.com/nokia/robotframework-autoitlibrary
in the root directory run the below command: python setup.py install using cmd in admin mode
to navigate to root directory use the command pushd <filepath>' instead ofcd ` if cd doesn't work in cmd opened in admin mode.
For 64:
Open cmd in "Run as administrator" mode
Now clone the autoit library source code:
https://github.com/nokia/robotframework-autoitlibrary
in the root directory run the below command: python setup.py install using cmd in admin mode
to navigate to root directory use the command pushd <filepath>' instead ofcd ` if cd doesn't work in cmd opened in admin mode.

How to Export a python project as an executable file? Project is a browser based one

I have a python project which has to be exported in to an executable file so that it can be used in other systems as well. The project has its UI in a browser and runs on localhost.
So far I have tried PyInstaller and cx_Freeze but to no success. I encountered some errors with PyInstaller which I was unable to solve and I switched to cx_Freeze. I was able to freeze the scripts and create a .exe file. But when I open(double click) the .exe file, I get nothing. Not even an error message. I tried running it from command prompt as well, but there too I got no message or output.
Can anyone suggest how my objective can be achieved? Or something needs to be checked?
Here is my setup.py
import sys
import os
from cx_Freeze import setup, Executable
base = None
#if sys.platform == "win32":
# base = "Win32GUI"
os.environ['TCL_LIBRARY']="C:\\Users\\M******\\AppData\\Local\\Continuum\\Anaconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY']="C:\\Users\\M******\\AppData\\Local\\Continuum\\Anaconda3\\tcl\\tk8.6"
setup ( name = "Network Analysis",
version = "0.1",
description = "Network Analysis Project",
options = { "build_exe": { "packages" : ['encodings','asyncio','pandas','numpy','geopy','networkx','configparser','json']}},
executables = [Executable("run.py",base=base)])

Use qjson in my Qt symbain app

I'm using Qt to develop a Symbian app.
I downloaded qjson from the link. I followed the instructions in that link and yes, I have the qjson.sis file. Now I need to use it in my app. When I tried, I got this error.
Launch failed: Command answer [command error], 1 values(s) to request: 'C|101|Processes|start|""|"MyProject.exe"|[""]|[]|true'
{"Code":-46,Format="Failed to create the process (verify that the executable and all required DLLs have been transferred) (permission denied)"}
Error: 'Failed to create the process (verify that the executable and all required DLLs have been transferred) (permission denied)' Code: -46
And when I press the launch icon, it shows, "Unable to execute file for security reasons".
Then I install the qjson.sis in my mobile and then tried to install my app, I got this error.
:-1: error: Installation failed: 'Failed to overwrite file owned by another package: c:\sys\bin\qjson.dll in ' Code: 131073; see http://wiki.forum.nokia.com/index.php/Symbian_OS_Error_Codes for descriptions of the error codes
In my .pro file I have this.
symbian: {
addFiles.sources = qjson.dll
addFiles.path = /sys/bin
DEPLOYMENT += addFiles
}
symbian: {
LIBS += -lqjson
}
Any ideas...?
Ok, I've just resolved a similar issue: it seems that your current build of QJson's library has different UID3 than the previous one that you installed on the phone.
Each .SIS file that is installed on the device has an identifier. The phone OS tracks which file was installed by which packacge, and if some new package wants to overwrite an existing file, the OS checks whether the new package has the same 'identity' than the previous owner of the file to be overwritten.
If the identity does not match, this error pops up.
There are number of reasons why this could have happened. For example, you could have simply changed the UID3 of the QJson before the build. Or, maybe you have forgot to set the library's UID3? Check the "src.pro' in the QJson project and go to the half of the file, you'd see lines:
#TARGET.UID3 =
TARGET.CAPABILITY = ReadDeviceData WriteDeviceData
If there's #, then you have forgot to set it and the build process assumed, well, letssay 'a random value'. So, now, set it to something, ie. TARGET.UID3 = 0xE0123456. Remember to correct that once you are ready to publish the application.
If a package with broken UID3 gets onto your phone and is blocking something - simply: uninstall it. Go to Settings/Installations/Installed, then find "qjson" and uninstall it. Afterwards, next installtion of qjson should succeed with no problems.

problems with monkeyrunner

I am working on making some changes to the android framework layer and building my own version. I am working based on froyo and trying to use monkeyrunner for some testing. I have pulled the source and can build and run in the emulator but when I try to use a monkeyrunner script I can't seem to get anyhting to work. I built the code using lunch full-eng and it runs fine on the device. I am just trying to get a simple script running based on the example at http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html shown below with a print statement added just to see if I could get anything to run.
/# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
/# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
print "Hello World!"
When the following line is in the script I get an error as follows.
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
Traceback (most recent call last):
File "../../MRTesting/MyTest.py, line 4, in
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
ImportError: cannot import name MonkeyDevice
So if I remove MonkeyDevice from the import as shown below I get a different error on the call to waitForConnection()
from com.android.monkeyrunner import MonkeyRunner
Traceback (most recent call last):
File "../../MRTesting/MyTest.py, line 6, in
device = MonkeyRunner.waitForConnection()
AttributeError: type object 'com.android.monkeyrunner.MonkeyRunner' has no attribute 'waitForConnection'
I tried modifying the call to have some arguments as indicated in the documentation as follows but I still get the same error. The second argument matches the value returned by a call to adb devices.
device = MonkeyRunner.waitForConnection(5, 'emulator-5554')
I have done some digging around and one person said that the shebang needs to be at the beginning of the file as follows with the path modified to avoid putting information in I would rather not share.
/#! /home/<path>/monkeyrunner
I could not see how this would be any different than me invoking monkeyrunner directly from the command line but I tried it and no luck. I did not install the sdk anywhere on my system as it is included in the build tree but it seems to me that the monkeyrunner tool might not be able to locate it as needed but I can't find any indication of how to fix this. I am running the following commands when I build my system from within my build directory at the root.
. build/envsetup.sh
setpaths
lunch full-eng
make -j16
Anyone have any thoughts on this?

Resources