yashaka / selene

User-oriented Web UI browser tests in Python
https://yashaka.github.io/selene/
MIT License
690 stars 148 forks source link

Appium session is terminated or not started #208

Open Bochkarev90 opened 4 years ago

Bochkarev90 commented 4 years ago

First of all, thank you very much for your lib. I find it really useful for my project.

But I have a problem when trying to start appium driver. My code is very simple but it doesn't work Selene version: 2.0.0a22

from appium import webdriver
from selene.api import *

desired_caps = {
    "browserName": "Android",
    "platformName": "Android",
    "automationName": "uiautomator2",
    "deviceName": "Android Emulator",
    "app": "C:/Users/mbochkarev/Desktop/ePRO_1.0.8_build_4_test-signed.apk",
    "appPackage": "com.dmmatrix.epro.test",
    "appWaitActivity": "com.dmmatrix.epro.presentation.view.activity.AuthorizationActivity",
}
browser.config.driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)
s(by.id('com.dmmatrix.epro.test:id/etAccessCode')).type('test')

I have an exception:

Traceback (most recent call last):
  File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\core\wait.py", line 82, in for_
    return fn(self._entity)
  File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\core\wait.py", line 57, in __call__
    return self._fn(entity)
  File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\core\entity.py", line 207, in fn
    webelement = element()
  File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\core\entity.py", line 152, in __call__
    return self._locator()
  File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\core\locator.py", line 34, in __call__
    return self._locate()
  File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\core\entity.py", line 1086, in <lambda>
    lambda: self.driver.find_element(*by)),
  File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\support\shared\browser.py", line 56, in driver
    webdriver: WebDriver = self.config.driver
  File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\support\shared\config.py", line 129, in driver
    stored.quit()  # todo: can this raise exception? that we need to supress...
  File "D:\pythonProjects\behave_test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 698, in quit
    self.execute(Command.QUIT)
  File "D:\pythonProjects\behave_test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "D:\pythonProjects\behave_test\venv\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response
    raise wde
  File "D:\pythonProjects\behave_test\venv\lib\site-packages\appium\webdriver\errorhandler.py", line 24, in check_response
    super(MobileErrorHandler, self).check_response(response)
  File "D:\pythonProjects\behave_test\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: A session is either terminated or not started

I found that the issue is in the driver getter method: image If i just write "is_alive = True" than my code is working as expected. Think android app doesn't have "title" property so we have a problem

yashaka commented 4 years ago

Oh!

Yeah, seems like appium driver has no title method! I will try to fix it soon!

On Tue, Apr 7, 2020, 11:43 Бочкарев Максим notifications@github.com wrote:

First of all, thank you very much for your lib. I find it really useful for my project.

But I have a problem when trying to start appium driver. My code is very simple but it doesn't work Selene version: 2.0.0a22

from appium import webdriver from selene.api import *

desired_caps = { "browserName": "Android", "platformName": "Android", "automationName": "uiautomator2", "deviceName": "Android Emulator", "app": "C:/Users/mbochkarev/Desktop/ePRO_1.0.8_build_4_test-signed.apk", "appPackage": "com.dmmatrix.epro.test", "appWaitActivity": "com.dmmatrix.epro.presentation.view.activity.AuthorizationActivity", } browser.config.driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps) s(by.id('com.dmmatrix.epro.test:id/etAccessCode')).type('test')

I have an exception:

Traceback (most recent call last): File "D:\pythonProjects\behavetest\venv\lib\site-packages\selene\core\wait.py", line 82, in for return fn(self._entity) File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\core\wait.py", line 57, in call return self._fn(entity) File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\core\entity.py", line 207, in fn webelement = element() File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\core\entity.py", line 152, in call return self._locator() File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\core\locator.py", line 34, in call return self._locate() File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\core\entity.py", line 1086, in lambda: self.driver.find_element(*by)), File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\support\shared\browser.py", line 56, in driver webdriver: WebDriver = self.config.driver File "D:\pythonProjects\behave_test\venv\lib\site-packages\selene\support\shared\config.py", line 129, in driver stored.quit() # todo: can this raise exception? that we need to supress... File "D:\pythonProjects\behave_test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 698, in quit self.execute(Command.QUIT) File "D:\pythonProjects\behave_test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "D:\pythonProjects\behave_test\venv\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response raise wde File "D:\pythonProjects\behave_test\venv\lib\site-packages\appium\webdriver\errorhandler.py", line 24, in check_response super(MobileErrorHandler, self).check_response(response) File "D:\pythonProjects\behave_test\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: A session is either terminated or not started

I found that the issue is in the driver getter method: [image: image] https://user-images.githubusercontent.com/22298126/78648355-8647d880-78c4-11ea-923b-c987616aa4c9.png If i just write "is_alive = True" than my code is working as expected. Think android app doesn't have "title" property so we have a problem

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/yashaka/selene/issues/208, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAO6ZHT46QW67K2PSAN3R33RLLRRTANCNFSM4MC5TRXQ .

yashaka commented 4 years ago

@Bochkarev90 , seems like it will not be like that easy... I am not sure the problem is with Title.... Appium should support title too... Maybe no, but for now I have not find information that "it will not work with title for sure"...

I have to research more on this... Try it on my own...

For now, you can consider using explicit browser, instead of shared browser...

image

then you will control the driver management on your side...

another thing what you can try is instead of "is_alive = True" - change the .title part to something else... that might work... Maybe you will try a better alternative for checking driver status in a "multi-platform (web/mogile" way...