PyCharm reports OSError [WinError 193]

It was working fine code extract:

 

login_test.py

import os   (at the top of file)

def driver(self, request):
_geckodriver = os.path.join(os.getcwd(), 'vendor', 'geckodriver')
driver_ = webdriver.Firefox(executable_path=_geckodriver)


login_test.py


def test_valid_credentials(self, driver):
driver.get("http://the-internet.herokuapp.com/login")
driver.find_element(By.ID, "username").send_keys("tomsmith")
driver.find_element(By.ID, "password").send_keys("SuperSecretPassword!")
driver.find_element(By.CSS_SELECTOR, "button").click()
assert driver.find_element(By.CSS_SELECTOR, ".flash_success").is_displayed()



Full text of error:

C:\Users\brian.jowers\Projects\myproject>py.test
============================= test session starts =============================
platform win32 -- Python 3.7.2, pytest-4.0.2, py-1.7.0, pluggy-0.8.0
Using --randomly-seed=1547119574
rootdir: C:\Users\brian.jowers\Projects\myproject, inifile:
plugins: xdist-1.25.0, randomly-1.2.3, forked-0.2
collected 1 item

tests\login_test.py E [100%]

=================================== ERRORS ====================================
_____________ ERROR at setup of TestLogin.test_valid_credentials ______________

self = <tests.login_test.TestLogin object at 0x000001BBE1F9F198>
request = <SubRequest 'driver' for <Function 'test_valid_credentials'>>

@pytest.fixture
def driver(self, request):
_geckodriver = os.path.join(os.getcwd(), 'vendor', 'geckodriver')
> driver_ = webdriver.Firefox(executable_path=_geckodriver)

tests\login_test.py:13:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c:\python37\lib\site-packages\selenium\webdriver\firefox\webdriver.py:164: in __init__
self.service.start()
c:\python37\lib\site-packages\selenium\webdriver\common\service.py:76: in start
stdin=PIPE)
c:\python37\lib\subprocess.py:775: in __init__
restore_signals, start_new_session)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <subprocess.Popen object at 0x000001BBE2EBF8D0>
args = 'C:\\Users\\brian.jowers\\Projects\\myproject\\vendor\\geckodriver --port 63353'
executable = None, preexec_fn = None, close_fds = False, pass_fds = ()
cwd = None
env = environ({'PROMPT': '$P$G', 'TEMP': 'C:\\Users\\BRIAN~1.JOW\\AppData\\Local\\Temp', 'COMSPEC': 'C:\\WINDOWS\\system32\\...al\\Microsoft\\Wind
owsApps;', 'PYTEST_CURRENT_TEST': 'tests/login_test.py::TestLogin::test_valid_credentials (setup)'})
startupinfo = <subprocess.STARTUPINFO object at 0x000001BBE2EBF908>
creationflags = 0, shell = False, p2cread = Handle(752), p2cwrite = 13
c2pread = -1, c2pwrite = Handle(764), errread = -1, errwrite = Handle(768)
unused_restore_signals = True, unused_start_new_session = False

def _execute_child(self, args, executable, preexec_fn, close_fds,
pass_fds, cwd, env,
startupinfo, creationflags, shell,
p2cread, p2cwrite,
c2pread, c2pwrite,
errread, errwrite,
unused_restore_signals, unused_start_new_session):
"""Execute program (MS Windows version)"""

assert not pass_fds, "pass_fds not supported on Windows."

if not isinstance(args, str):
args = list2cmdline(args)

# Process startup details
if startupinfo is None:
startupinfo = STARTUPINFO()
else:
# bpo-34044: Copy STARTUPINFO since it is modified above,
# so the caller can reuse it multiple times.
startupinfo = startupinfo._copy()

use_std_handles = -1 not in (p2cread, c2pwrite, errwrite)
if use_std_handles:
startupinfo.dwFlags |= _winapi.STARTF_USESTDHANDLES
startupinfo.hStdInput = p2cread
startupinfo.hStdOutput = c2pwrite
startupinfo.hStdError = errwrite

attribute_list = startupinfo.lpAttributeList
have_handle_list = bool(attribute_list and
"handle_list" in attribute_list and
attribute_list["handle_list"])

# If we were given an handle_list or need to create one
if have_handle_list or (use_std_handles and close_fds):
if attribute_list is None:
attribute_list = startupinfo.lpAttributeList = {}
handle_list = attribute_list["handle_list"] = \
list(attribute_list.get("handle_list", []))

if use_std_handles:
handle_list += [int(p2cread), int(c2pwrite), int(errwrite)]

handle_list[:] = self._filter_handle_list(handle_list)

if handle_list:
if not close_fds:
warnings.warn("startupinfo.lpAttributeList['handle_list'] "
"overriding close_fds", RuntimeWarning)

# When using the handle_list we always request to inherit
# handles but the only handles that will be inherited are
# the ones in the handle_list
close_fds = False

if shell:
startupinfo.dwFlags |= _winapi.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = _winapi.SW_HIDE
comspec = os.environ.get("COMSPEC", "cmd.exe")
args = '{} /c "{}"'.format (comspec, args)

# Start the process
try:
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
# no special security
None, None,
int(not close_fds),
creationflags,
env,
os.fspath(cwd) if cwd is not None else None,
> startupinfo)
E OSError: [WinError 193] %1 is not a valid Win32 application

c:\python37\lib\subprocess.py:1178: OSError
=========================== 1 error in 0.30 seconds ===========================

 

2 comments
Comment actions Permalink

Hi Brian,

Sorry for replying so late. Does the issue only happen when you're running test? Is the code working when you run it? From the first look, it doesn't seem to be IDE issue. It can be some library missing from PATH, or incompatibility between 32-bit / 64-bit library.

Can you run the same test from outside PyCharm?

0
Comment actions Permalink

Fixed the problem, problem was with 'geckodriver' somehow it was corrupted.

New download and everything was working.

0

Please sign in to leave a comment.