Closed AltTesterBot closed 1 year ago
Thanks for the bug report! I would need your help a bit more to narrow down the problem, if you have the time, could you please check the following?
To use the AltUnityDriver, you need to:
Import the AltUnityTester asset/package into your Unity project:
AltUnityTester.unitypackage
fileAdd the AltUnityDriver prefab (from AltUnityTester/Prefab folder) to your main scene in the game/app, the one that will be first shown to the users. By default, this will use 13000
as the port for the socket connection.
If you want to change this, you can update the port value number in Unity Editor in the Inspector.
To run your tests on iOS and Android, you need to have Appium installed. Info on that is available here: http://appium.io/docs/en/about-appium/getting-started
For iOS, to run the tests on real iOS device, please make sure you also go through this: http://appium.io/docs/en/drivers/ios-xcuitest/
To connect to the AltUnityDriver socket connection, with the device connected to your computer, you will need to forward the tcp port from the device to your computer:
To do this on Android, use:
adb forward tcp:13001 tcp:13000
where first port (13001 in the example above) is the port on your computer and the second port (13000 in the example above) is the AltUnityDriver port. This is 13000 by default.
To do this on iOS, use:
iproxy 13002 13000
where first port (13002 in the example above) is the port on your computer and the second port (13000 in the example above) is the AltUnityDriver port. This is 13000 by default.
The iproxy
command is installed as part of the libimobiledevice package that you should have already installed when setting up your iOS environment (http://appium.io/docs/en/drivers/ios-xcuitest-real-devices/)
You can find the original comment from GitLab here.
Thank you for the answer. Yes, I added AltUnityTester prefab to my scene in Unity using part of setup. I set up my local machine.
I tested with Development build and without it and I had the same issue. Added to attachments Appium logs.
[Logcat] Starting logcat capture
[AndroidDriver] Pushing unlock helper app to device...
[ADB] Getting install status for io.appium.unlock
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","pm","list","packages","io.appium.unlock"]
[ADB] App is installed
[ADB] Getting package info for io.appium.unlock
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","dumpsys","package","io.appium.unlock"]
[ADB] Checking whether aapt is present
[ADB] Using aapt from .../Library/Android/sdk/build-tools/27.0.3/aapt
[ADB] The installed 'io.appium.unlock' package does not require upgrade ('2.0.0' >= '2.0.0')
[ADB] Getting device platform version
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","getprop","ro.build.version.release"]
[ADB] Current device property 'ro.build.version.release': 4.3
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","wm","size"]
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","getprop","ro.product.model"]
[ADB] Current device property 'ro.product.model': GT-I9300
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","getprop","ro.product.manufacturer"]
[ADB] Current device property 'ro.product.manufacturer': samsung
[AndroidDriver] Parsing package and activity from app manifest
[ADB] Using apkanalyzer from .../Library/Android/sdk/tools/bin/apkanalyzer
[ADB] Starting '.../Library/Android/sdk/tools/bin/apkanalyzer' with args ["-h","manifest","print",".../Documents/appodeal/unity/New Unity Project/build.apk"]
[ADB] Using the alternative activity name detection method because of: Command '.../Library/Android/sdk/tools/bin/apkanalyzer -h manifest print '.../Documents/appodeal/unity/New Unity Project/build.apk'' exited with code 1
[ADB] Checking whether aapt is present
[ADB] Using aapt from .../Library/Android/sdk/build-tools/27.0.3/aapt
[ADB] Extracting package and launch activity from manifest
[ADB] Package name: 'com.appodeal.test'
[ADB] Main activity name: 'com.unity3d.player.UnityPlayerActivity'
[AndroidDriver] Parsed package and activity are: com.appodeal.test/com.unity3d.player.UnityPlayerActivity
[ADB] Getting install status for com.appodeal.test
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","pm","list","packages","com.appodeal.test"]
[ADB] App is installed
[ADB] Getting package info for com.appodeal.test
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","dumpsys","package","com.appodeal.test"]
[ADB] Checking whether aapt is present
[ADB] Using aapt from .../Library/Android/sdk/build-tools/27.0.3/aapt
[ADB] The installed 'com.appodeal.test' package does not require upgrade ('1.0.0' >= '1.0.0')
[AndroidDriver] Extracting strings from apk .../Documents/appodeal/unity/New Unity Project/build.apk undefined /var/folders/7v/rjq1bqj50v706mvxvb15dklc0000gn/T/com.appodeal.test
[ADB] Extracting strings for language: default
[ADB] Device API level: 18
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","getprop","persist.sys.language"]
[ADB] Current device property 'persist.sys.language': ru
[ADB] Reading strings from converted strings.json
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","push","/var/folders/7v/rjq1bqj50v706mvxvb15dklc0000gn/T/com.appodeal.test/strings.json","/data/local/tmp"]
[AndroidBootstrap] Watching for bootstrap disconnect
[ADB] Forwarding system: 4724 to device: 4724
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","forward","tcp:4724","tcp:4724"]
[UiAutomator] Starting UiAutomator
[UiAutomator] Moving to state 'starting'
[UiAutomator] Parsing uiautomator jar
[UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","push","/Applications/Appium.app/Contents/Resources/app/node_modules/appium-android-bootstrap/bootstrap/bin/AppiumBootstrap.jar","/data/local/tmp/"]
[ADB] Attempting to kill all uiautomator processes
[ADB] Getting all processes with uiautomator
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","ps"]
[ADB] No uiautomator process found to kill, continuing...
[UiAutomator] Starting UIAutomator
[ADB] Creating ADB subprocess with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","com.appodeal.test","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false]
[UiAutomator] Moving to state 'online'
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] json loading complete.
[AndroidBootstrap] Android bootstrap socket is now connected
[ADB] Getting connected devices...
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","dumpsys","window"]
[AndroidDriver] Screen already unlocked, doing nothing
[ADB] Device API level: 18
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","am","start","-W","-n","com.appodeal.test/com.unity3d.player.UnityPlayerActivity","-S"]
[ADB] Waiting up to 20000ms for activity matching pkg: 'com.appodeal.test' and activity: 'com.unity3d.player.UnityPlayerActivity' to be focused
[ADB] Possible activities, to be checked: 'com.unity3d.player.UnityPlayerActivity'
[ADB] Getting focused package and activity
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","dumpsys","window","windows"]
[ADB] Found package: 'com.appodeal.test' and fully qualified activity name : 'com.unity3d.player.UnityPlayerActivity'
[Appium] New AndroidDriver session created successfully, session d04ac9a5-0dce-4fca-a8fc-d8139db4e0f1 added to master session list
[BaseDriver] Event 'newSessionStarted' logged at 1524062494514 (17:41:34 GMT+0300 (EEST))
[MJSONWP] Responding to client with driver.createSession() result: {"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformVersion":"4.3","deviceName":"Samsung GT-l9300","app":".../Documents/appodeal/unity/New Unity Project/build.apk","platformName":"Android","noReset":true},"platformVersion":"4.3","deviceName":"4df1697a2b2e7f8d","app":"/.../Documents/appodeal/unity/New Unity Project/build.apk","platformName":"Android","noReset":true,"deviceUDID":"4df1697a2b2e7f8d","deviceScreenSize":"720x1280","deviceModel":"GT-I9300","deviceManufacturer":"samsung","appPackage":"com.appodeal.test","appWaitPackage":"com.appodeal.test","appActivity":"com.unity3d.player.UnityPlayerActivity","appWaitActivity":"com.unity3d.player.UnityPlayerActivity"}
[HTTP] <-- POST /wd/hub/session 200 15643 ms - 939
[BaseDriver] Shutting down because we waited 60 seconds for a command
[AndroidDriver] Shutting down Android driver
[ADB] Getting connected devices...
[Appium] Closing session, cause was 'New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability'
[Appium] Removing session d04ac9a5-0dce-4fca-a8fc-d8139db4e0f1 from our master session list
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","am","force-stop","com.appodeal.test"]
[ADB] Pressing the HOME button
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","input","keyevent",3]
[AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":"OK, shutting down","status":0}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Closed client connection
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: current=1
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=.
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: numtests=1
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: 0
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=
[AndroidBootstrap] [UIAUTO STDOUT] Test results for WatcherResultPrinter=.
[AndroidBootstrap] [UIAUTO STDOUT] Time: 64.814
[AndroidBootstrap] [UIAUTO STDOUT] OK (1 test)
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: -1
[AndroidBootstrap] Received command result from bootstrap
[UiAutomator] Shutting down UiAutomator
[UiAutomator] Moving to state 'stopping'
[UiAutomator] UiAutomator shut down normally
[UiAutomator] Moving to state 'stopped'
[ADB] Attempting to kill all uiautomator processes
[ADB] Getting all processes with uiautomator
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","ps"]
[ADB] No uiautomator process found to kill, continuing...
[UiAutomator] Moving to state 'stopped'
[Logcat] Stopping logcat capture
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '.../Library/Android/sdk/platform-tools/adb' with args: ["-P",5037,"-s","4df1697a2b2e7f8d","shell","am","force-stop","io.appium.unlock"]
[AndroidDriver] Not cleaning generated files. Add `clearSystemFiles` capability if wanted.
---
<sub>You can find the original comment from GitLab [here](https://gitlab.com/altom/altunity/altunitytester/-/issues/10#note_69177334).</sub>
Thank you, that all looks good. Would it be possible to also get the Android logcat? You can save it to a file using this command:
adb logcat -f logcat.txt
You can find the original comment from GitLab here.
The logs show that the AltUnityTester starts correctly inside the game, so the issue must be on the other side. It could be a firewall problem?
I can suggest a few more things:
After you forward the ADB port using adb forward tcp:13001 tcp:13000
command, try to restart the game on the device and check if the connection really works.
I'm not sure what operating system you are on, but you could try:
telnet localhost 13001
to see if you can connect on the socket.
(On Mac, you can install telnet
with brew install telnet
if you don't have it already.)
Or you could just try to go to "http://localhost:13001" in your browser - if the connection is open, you should see the page keeps loading instead of just saying it cannot connect.
Do any of these work?
Try to get the device's IP address and connect to that directly in your tests, if your device is on the same Wi-Fi network as the local machine that you run the tests from. So, if the device has the IP address 192.168.1.123
, try to create the AltUnityDriver like this in the Python tests:
self.altdriver = AltrunUnityDriver(self.driver, self.platform, TCP_IP="192.168.1.123", TCP_FWD_PORT=13000)
Also if you want you can find me on Skype with ru_cindrea, we could maybe discuss it more easily there and try to solve the problem.
You can find the original comment from GitLab here.
Hi,
I had this same problem but fixed it with the following:
In AltSocketServer.cs in the Unity package the device IP address is set to "127.0.0.1", if you change it to the device's ip address as it appears on the network (e.g. "192.168.0.20") then you should be able to connect to the socket from another device.
Bex
-- edit: Removed incorrect information regarding switching TCP ports, I was confused! The former point still stands though
You can find the original comment from GitLab here.
I ran into this issue as well during my initial trial. Following the thread of @bexelfee above I found that if I modified the server endpoint setup to use IPAddress.Any rather than localhost (127.0.0.1) it resolved the issue for me. I guess there are situations where adb forward doesn't map the tcp calls to localhost on the device?
this.localEndPoint = new IPEndPoint(IPAddress.Any, this.portNumber);
You might want to give that a try and see if it works in all cases. More info can be found under the "Remarks" section of the TcpListener class here: https://msdn.microsoft.com/en-us/library/c6z86e63(v=vs.110).aspx.
You can find the original comment from GitLab here.
Can someone explain where else 13001 is defined? I am forwarding the port but still hit this issue. What server did I set up that takes 13001 as a port config (or is it a default?)?
You can find the original comment from GitLab here.
Ah I think I see now. Forwarding the port is supposed to allow access to the device by sending traffic to localhost 13001 on the computer. In the e.g. python test client script you specify 13001 when you construct AltUnityDriver to connect to the device. The device listens on 13000 which should be traffic forwarded from the 13001 port that the python test client script sends to. The python test client script also uses 4723 or whatever your appium server is set to when you call webdriver.Remote()
.
Okay it turns out my problem was that I did not know that in order to try new code on the device, you have to copy the apk to the device and install it manually. I also learned that by default adb logcat -f logcat.txt
won't work on most devices because that attempts to write to the device OS system root which is generally not allowed. Instead I used adb logcat > logcat.txt
which dumps it to a text file in your current directory on your desktop computer. Also I learned that you don't get to see the unity debug output just by running the app and saving logcat, you have to do an actual test (appium must be instrumenting something) either with py.test or python mytest.py in order to see the Unity debug output. I only tried development/debug build so that may be required too. I use python mytest.py while writing tests because it lets me see my python print() statements, while py.test does not.
As of this week I was only able to get this working in Unity2018.2.8f1 by uninstalling python 3 and installing python 2.7 as it comes through from appium python client recommended steps. Appium desktop didn't seem to work so I installed the npm command line version. I had to run npm --add-python-to-path='true' --debug install --global windows-build-tools
and then add C:\Users\<username>\.windows-build-tools\python27\
manually so both it and C:\Users\<username>\.windows-build-tools\python27\Scripts
were added to PATH before I could install pip and then finally run pip install -U pytest
and pip install altunityrunner==0.2.3
(newer altunityrunner did not compile for me, possibly because of having python 3 only installed) though probably another decent python installer would have worked too. I had to roll back to the unitypackage file from commit 32c572a6ac47c49b566202cef75315e9159d910f in this repo.
Here is the test I used (based on the adventure game testing youtube video) which would not work until I had tweaked one or two things (e.g. the new self.platform parameter). adventure-tests.py
I hope this helps others who come along trying to get this working on Windows. Maybe some of this would be good to add to the main readme? Let me know if you want a merge request for that and if so which points you think would be relevant to others. Thanks to those that helped make this awesome tool!
You can find the original comment from GitLab here.
Is it possible to run to a device connected remotely? My issue is something similar to the one. My device is connected on a different server say 192.168.1.15. My tests are executed on a different server - 192.168.1.20. I have done port forwarding on 192.168.1.15 and when I call the statement AltRunUnityDriver, I give like this
AltrunUnityDriver(driver, platform=None,TCP_IP='192.168.1.15', TCP_PORT=13000, TCP_FORWARD_PORT=13000, requestEnd='#')
This doesn't work. I have to always copy the script to 192.168.1.15 to run the script. Is there a solution to this? cc: @ru.cindrea
You can find the original comment from GitLab here.
Hi @thejuskrishna! It is possible to run to a device remotely. Just change the IP address from AltSocketServer.cs to "0.0.0.0". Should look like this:
System.Net.IPAddress ipAddress = System.Net.IPAddress.Parse("0.0.0.0");
After that you should be able to connect to the phone without doing port forwarding. Just make sure that you put the phone IP in tests.
You can find the original comment from GitLab here.
I am trying to automate iOS Unity Game App. Why is my below code throwing me SessionNotCreatedException ?
`@BeforeClass public static void setUp() throws IOException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "iOS");
caps.setCapability("deviceName", "CAREDeviPad");
caps.setCapability("platformVersion", "12.4.9");
caps.setCapability("udid", "DeviceUDID");
caps.setCapability("automationName", "XCUITest");
caps.setCapability("noReset", true);
caps.setCapability("waitForQuiescence", false);
File f = new File(System.getProperty("user.dir"));
File fs = new File(f, "src/test/java/apps/AltUnityPoC.ipa");
caps.setCapability("app", fs.getAbsolutePath());
URL url = new URL("http://127.0.0.1:4723/wd/hub");
driver = new AppiumDriver<MobileElement>(url, caps);
AltUnityDriver.setupPortForwarding("iOS", "DeviceUDID", 13000, 13000);
altdriver = new AltUnityDriver();
}`
Below is my log,
[RemoteTestNG] detected TestNG version 7.3.0
FAILED CONFIGURATION: @BeforeClass setUp
org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Bad app: /Users/gsn/eclipse-workspace/MavenUnityProjectTest/src/test/java/apps/AltUnityPoC.ipa. App paths need to be absolute or an URL to a compressed app file: end of central directory record signature not found
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'Mac-mini.local', ip: '127.0.0.1', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.7', java.version: '14.0.2'
Driver info: driver.version: AppiumDriver
remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Bad app: /Users/gsn/eclipse-workspace/MavenUnityProjectTest/src/test/java/apps/AltUnityPoC.ipa. App paths need to be absolute or an URL to a compressed app file: end of central directory record signature not found
at getResponseForW3CError (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:804:9)
at asyncHandler (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:381:37)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'Mac-mini.local', ip: '127.0.0.1', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.7', java.version: '14.0.2'
Driver info: driver.version: AppiumDriver
at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:208)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:336)
at org.openqa.selenium.remote.RemoteWebDriver.
You can find the original comment from GitLab here.
I have an app generated by Unity( iOS and Android).
I started an Appium server. I wrote the small test on python (on both of platforms Android and iOS) and I had an error (AltUnityServer not running on port 13001) I tested on both of platforms Android and iOS on simulators and real devices.
You can find the original issue from GitLab here.