RobotFramework - AutoItLibrary: Importing test lib

2019-06-03 11:29发布

Can anyone support me this case?

I install the same steps in 2 machines with similar configurations. But one machine works. One machine fails when importing AutoItLibrary.

View Ride log - the error shows:

  20190322 16:34:04.751 [WARN]: Importing test library "AutoItLibrary" failed

Traceback (most recent call last):
Initializing test library 'AutoItLibrary' with no arguments failed: com_error: (-2147221008, 'CoInitialize has not been called.', None, None)
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 167, in _get_instance
    return libcode(*self.positional_args, **dict(self.named_args))
  File "C:\Python27\lib\site-packages\AutoItLibrary\__init__.py", line 84, in __init__
    self._AutoIt = win32com.client.Dispatch("AutoItX3.Control")
  File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
  File "C:\Python27\lib\site-packages\robotide\spec\librarymanager.py", line 87, in _fetch_keywords
    return get_import_result(path, library_args)
  File "C:\Python27\lib\site-packages\robotide\spec\libraryfetcher.py", line 24, in get_import_result
    lib = robotapi.TestLibrary(path, args)
  File "C:\Python27\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 54, in TestLibrary
    lib.create_handlers()
  File "C:\Python27\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 100, in create_handlers
    self._create_handlers(self.get_instance())
  File "C:\Python27\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 159, in get_instance
    self._libinst = self._get_instance(self._libcode)
  File "C:\Python27\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 169, in _get_instance
    self._raise_creating_instance_failed()
  File "C:\Python27\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 314, in _raise_creating_instance_failed
    % (self.name, args_text, msg, details))


20190322 16:34:05.048 [INFO]: Found Robot Framework version 3.1.1 from C:\Python27\lib\site-packages\robot.

20190322 16:34:05.048 [INFO]: Started RIDE 1.7.3.1 using python version 2.7.14 with wx version 4.0.4 in win32.

2条回答
倾城 Initia
2楼-- · 2019-06-03 11:37
@echo off
setlocal

set "jsfile=%temp%\autoit3x_comtest.js"

(
    echo try {
    echo     oAutoIt = new ActiveXObject("AutoItX3.Control"^);
    echo }
    echo catch (e^) {
    echo     WScript.Echo("Catch: " + e^);
    echo     WScript.Quit (1^);
    echo }
) > "%jsfile%"

set "system=System32"

if /i not "%PROCESSOR_ARCHITECTURE%" == "x86" (
    set "system=SysWOW64"
)

echo Using: %system%

"%SYSTEMROOT%\%system%\cscript.exe" //nologo "%jsfile%"
if not errorlevel 1 (
    echo No error detected.
    goto :done
)

>nul 2>nul net session
if errorlevel 1 (
    if not exist "AutoItX3.dll" if not exist "AutoItX3_x64.dll" goto :done
    echo Require to run as admin to register any dlls.
    goto :done
)

if exist "AutoItX3.dll" (
    echo Register AutoItX3.dll
    for %%A in ("/u" "") do (
        "%SYSTEMROOT%\%system%\regsvr32.exe" /s %%~A "AutoItX3.dll"
    )
)

if exist "AutoItX3_x64.dll" if exist "%SYSTEMROOT%\SysWOW64" (
    echo Register AutoItX3_x64.dll
    for %%A in ("/u" "") do (
        "%SYSTEMROOT%\System32\regsvr32.exe" /s %%~A "AutoItX3_x64.dll"
    )
)

:done
del "%jsfile%"

I suspect the AutoItX3.dll is not registered, which outputs a COM error.

The code above is batch-file, so you could save it as e.g. autoitx_comtest.cmd. It uses JScript to try to load the AutoItX3.Control object. If it fails and the script is running as admin, it will register the dlls if exist in the directory.

AutoitLibrary usually only provides the 32 bit dll, which is AutoItX3.dll. If you want 64 bit as well, add AutoItX3_x64.dll to the directory to be registered. If you have AutoIt3 installed, then you may already have the dlls registered by the installer.

If you have Python 64 bit installed, then AutoItX3_x64.dll may be required to use AutoItLibrary with it as 64 bit executables cannot use 32 bit dlls and vice versa.

Note: If you know how to register dlls with regsvr32, then you could just use that instead of the batch-file.

Compatibility with additional dlls

For compatibility with AutoItLibrary using an older version 3.3.6.0 of AutoItX3.dll. I could recommend using dlls from the archived versions and downloading autoit-v3.3.6.0-sfx.exe to get the dlls. In the latest AutoItX version, some methods were removed, such as RegRead. Also, the AutoItLibrary author may not support any version other than 3.3.6.0.

If you have the latest AutoIt Installer installed, then you may need to unregister those dlls and ensure the 3.3.6.0 dlls are registered to be compatible. I am unsure if you can have different versions of the dlls registered at the same time, on the same system.

The latest version of AutoItX dlls may work quite well, but AutoItLibrary keywords listed in the Documentation, such as Reg Read, Reg Write and some others may not be available as the methods were removed from the latest versions.

Latest vs compatibility, your choice.

查看更多
神经病院院长
3楼-- · 2019-06-03 11:54

I had the same problem and tested with 32 bit library then worked.

查看更多
登录 后发表回答