问题描述
我已使用在Unity Editor中运行的AltUnity Tester在Python中为Unity应用成功执行了自动化测试脚本。但是,在IOS Simulator中执行相同的Python脚本时遇到问题。我可以建立与13000服务器的连接,但是在尝试与元素交互时会出错。
这是编辑器代码:
import os
import unittest
import time
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
#from altunityrunner import AltrunUnityDriver
#from altunityrunner import By
from altunityrunner import *
class SimulatorTest(unittest.TestCase):
altdriver = None
@classmethod
def setUpClass(cls):
print("here we go!")
cls.altdriver = AltUnityDriver(None,'ios','127.0.0.1',13000,log_flag = True)
@classmethod
def tearDownClass(cls):
print("we're done!")
cls.altdriver.stop()
def test_play(cls):
time.sleep(10)
cls.altdriver.find_object(By.NAME,"AnimatedplayButton").tap()
print("Done")
cls.altdriver.stop()
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(SimulatorTest)
result = unittest.TextTestRunner(verbosity=2).run(suite)
sys.exit(not result.wasSuccessful())
这是IOS Simulator代码:
import os
import unittest
import time
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
#from altunityrunner import AltrunUnityDriver
#from altunityrunner import By
from altunityrunner import *
from selenium.webdriver.support.ui import webdriverwait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
class SimulatorTest(unittest.TestCase):
altdriver = None
platform = "ios"
@classmethod
def setUpClass(cls):
cls.desired_caps = {}
cls.desired_caps['platformName'] = 'iOS'
cls.desired_caps['deviceName'] = 'iPhone 11'
cls.desired_caps['automationName'] = 'XCUITest'
cls.desired_caps['platformVersion'] = '13.4'
app = os.path.abspath('/Users/domenicsorace/Desktop/Build/Products/ReleaseForRunning-iphonesimulator/twodotsdev.app')
cls.desired_caps['app'] = app
cls.driver = webdriver.Remote('http://localhost:4723/wd/hub',cls.desired_caps)
wait = webdriverwait(cls.driver,5)
# close the iOS pop up
element = wait.until(EC.element_to_be_clickable((MobileBy.ID,"Allow")))
cls.driver.switch_to.context('NATIVE_APP')
cls.driver.find_element_by_id("Allow").click()
cls.altdriver = AltUnityDriver(None,'192.168.0.3',log_flag = True)
@classmethod
def tearDownClass(cls):
cls.altdriver.stop()
def test_play(cls):
cls.altdriver.find_object(By.NAME,"AnimatedplayButton").tap()
print("Done")
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(SimulatorTest)
result = unittest.TextTestRunner(verbosity=2).run(suite)
sys.exit(not result.wasSuccessful())
错误:
2020-09-18 15:41:34.730 | DEBUG | altunityrunner.commands.base_command:recvall:46 - Received data was: error:unkNownError;System.Exception: Expected / or // instead of None
at Assets.AltUnityTester.AltUnityServer.AltUnityBaseClassFindobjectsCommand.SetCondition (System.Collections.Generic.List`1[T] list) [0x00000] in <00000000000000000000000000000000>:0
at Assets.AltUnityTester.AltUnityServer.AltUnityBaseClassFindobjectsCommand.Processpath (System.String path) [0x00000] in <00000000000000000000000000000000>:0
at Assets.AltUnityTester.AltUnityServer.Commands.AltUnityFindobjectCommand.Execute () [0x00000] in <00000000000000000000000000000000>:0
at AltUnityCommand+<>c__displayClass0_0.<SendResponse>b__0 () [0x00000] in <00000000000000000000000000000000>:0
at AltResponseQueue.Cycle () [0x00000] in <00000000000000000000000000000000>:0
2020-09-18 15:41:34.730 | DEBUG | altunityrunner.commands.command_returning_alt_elements:get_alt_element:16 - error:unkNownError;System.Exception: Expected / or // instead of None
at Assets.AltUnityTester.AltUnityServer.AltUnityBaseClassFindobjectsCommand.SetCondition (System.Collections.Generic.List`1[T] list) [0x00000] in <00000000000000000000000000000000>:0
at Assets.AltUnityTester.AltUnityServer.AltUnityBaseClassFindobjectsCommand.Processpath (System.String path) [0x00000] in <00000000000000000000000000000000>:0
at Assets.AltUnityTester.AltUnityServer.Commands.AltUnityFindobjectCommand.Execute () [0x00000] in <00000000000000000000000000000000>:0
at AltUnityCommand+<>c__displayClass0_0.<SendResponse>b__0 () [0x00000] in <00000000000000000000000000000000>:0
at AltResponseQueue.Cycle () [0x00000] in <00000000000000000000000000000000>:0
解决方法
删除或评论此行:
from selenium.webdriver.common.by import By
By
中altunityrunner的定义被上面的行覆盖。