Transforming Gaming Excellence: A Deep Dive into Game Automation

Hike
Hike Blog
Published in
6 min readDec 29, 2023

--

By Dhiraj Aggarwal, Automation Team, Hike

Since diversifying into the gaming sector, Hike has ardently pursued breakthroughs in game development. Now, we’re taking a giant leap forward with our latest exploration into game automation. This blog will guide you through the impactful integration of Unity, Appium, and AltTester, demonstrating how these tools collectively revolutionize the gaming automation experience.

Importance of Automation in Gaming

Automation testing plays a pivotal role in shaping game quality, ensuring that games meet high-quality standards, provide seamless experiences, and stay abreast of the needs of an increasingly varied and expanding gaming community. From the early days of pixelated adventures to today’s sophisticated open worlds, the expectations for gaming experiences have soared. Players now seek flawlessly executed narratives, engaging gameplay, and glitch-free environments. Meeting these expectations requires a rigorous testing process, and automation testing has become a game-changer in achieving these standards.

Let’s discuss why Rush Gaming Automation sets itself apart from the Native Only App. Let’s talk about Potential Challenges.

Challenges we faced in Game Automation

  • Dynamic Environments and Real-Time Interactions: Testing dynamic environments and real-time interactions in multiplayer or live-service games presents a challenge
  • Interpreting Game Elements: It’s about analyzing how these elements interact to engage and challenge players
  • Compatible Build Creations: Build creation is a complex process and takes multiple integrations of Unity, Appium, and AltTester with the main app code
  • Simulating Player Moves: For multiplayer game testing, it’s essential to have a system that can mimic the gameplay actions of adversaries. To achieve this, we created a simulator to generate player moves named “Simulated-Moves-Generator”

We started with a coordinate-based framework, which was very efficient in determining click position but faced challenges in asserting anything. Let’s dive deep into it.

Game Automation Framework: V1

No sea without waves. Game Automation is no exception. Even version V1 came with a lot of technical challenges. We pioneered a Smart Coordinate-Based Element Detection Framework while building version V1 for Game Automation. This framework helped us harness the game screen coordinates precisely after rendering.

📈Pros:

  • Innovatively integrated Unity with native Automation tool — Espresso
  • Enhanced user interactions, helping with performance automation
  • Ensured accurate click points on static interfaces

📉Cons:

  • Difficulty adapting to the ever-evolving complexities of games
  • Inaccurate recording of positions for dynamic elements
  • Encountered issues in element assertions due to the inability to access layout XMLs

However, despite meeting our immediate requirements, it became apparent that this approach wouldn’t stand the test of time. After putting in a handful of effort, we finalized AltTester. Building an effective framework, however, required countless late nights. Let us present a unique yet robust Game Automation Framework.

Intelligent Game Automation Framework: V2

In our quest for a stronger solution, AltTester proved to be the pivotal shift. By leveraging the capabilities of Appium and melding it with Unity’s adaptability, AltTester revamped our approach to Game Automation. Not to mention, we encountered multiple hurdles while building a robust Game Automation.

💡Let’s take a deeper look.

Seamless AltTester Integration with Unity Code:

The POC wasn’t a walk in the park. It took us about a month to embed the AltTester SDK within the Unity Game codebase, and yes, it’s crucial to note that the AltTester code has to be meticulously integrated with the game core code.

Let’s now delve into our process:

  • Firstly, we incorporated the AltTester SDK package into our Unity Game project
  • Following that, we assigned AltTester IDs to each Game Object. We accomplished this task by crafting a script

var instrumentationSettings = new AltInstrumentationSettings();

instrumentationSettings.ShowPopUp = true;

instrumentationSettings.InputVisualizer = true;

instrumentationSettings.AltTesterPort = 13000;

foreach (string scene in scenes){

AltBuilder.InsertAltInScene(scene, instrumentationSettings);

}

EditorUserBuildSettings.SwitchActiveBuildTarget (build_target);

Unified Build Creation using Native-Unity-AltTester:

Following our successful integration with AltTester, the subsequent hurdle was the Build creation. Could you believe this step was a significant milestone for us? Indeed, it was arguably the most challenging phase in our entire journey.

Here’s how we approached it, in a culinary metaphor:

  • We blended AltTester SDK into the Unity project, like mixing water into flour
  • This mixture was then kneaded to produce the Unity .so files
  • We then added the .so file into our native app’s codebase, like adding sweetener to the dough
  • Finally, we ‘baked’ the code to produce the desired .apk file 🍞

AltTester Port Forwarding:

To access the gaming element IDs and interaction on the gaming screens, AltTester provides Port Forwarding using an AltTester Server.

  • Once you install APK and launch it to access any Unity screen, the AltTester Server starts up.
  • The server works behind the TCP connection, which is set up using port forwarding. Port forwarding helps connect the commands received in the Appium Server to redirect to the AltTester Server. Read more about it here.

Wow! 😮‍💨Thought we were done? Nope, There’s more to come! The best is yet to come. Once our build was prepared, we optimistically believed that we were set to kick off the automation. Let’s move to the next step 🏋️

Building Appium Framework with Multi-Platform Support:

We started with an Appium Project and developed a solid framework. While it might sound straightforward, it required immense patience and countless iterations. It’s designed to handle Android, iOS, and Browser platforms seamlessly. Moreover, it offers the versatility to execute tests across three distinct environments: Local, Local Lab, and Remote Lab. (Stay tuned, as I’ll delve deeper into the Hike Automation Remote Lab in an upcoming blog post).

Setting up Appium Hub & Server with Intelligent Plugin Support:

You might be aware that running tests in Appium projects requires the Appium Server. For our setup, we established a hub and linked several Appium servers to it. However, merely running the Appium servers wasn’t enough. We had to create an additional plugin to facilitate the communication between the Appium server and the AltTester server (running on the device).

Versatile Jenkins Job Configurations:

We set up a Jenkins Pipeline for smooth game automation execution. This pipeline:

  • Initiates another Jenkins job to create the Build
  • Clones the Appium project from the GIT Repository
  • Once the build is ready, it executes the testng.xml using Maven
  • On completion, share the report

Simulated Moves Generator (SMG):

Simulating player moves for game automation is a complex task, especially when designed to act as opponents against client players. While basic moves follow predefined rules, creating one that understands game mechanics and strategies against other players presents a unique challenge. This requires a blend of game theory and deep learning.

🪜 Let’s see the execution of the complete Game Automation Flow

Game Automation Workflow

Fig: Image of Game Automation Infrastructure
  1. Embed AltTester SDK: Embed AltTester SDK into the Unity project to assign unique AltTester IDs to each game object
  2. Build Unity Project: Build the Unity project and generate .so files
  3. Incorporate .so Files: Incorporate these “.so” files into your native app’s codebase
  4. Compile .apk File: Compile the final build to create the “.apk” file ready for Automation
  5. Develop Appium Framework: Develop a robust Appium-based framework capable of handling multiple platforms (Android, iOS, and Browser)
  6. Setup Drivers & Port Forwarding: Setup the appiumDriver & altTesterDriver inside the Framework as well as port forwarding for altTesterDriver
  7. Establish Appium Hub: Establish an Appium hub and connect multiple Appium servers for distributed testing
  8. Develop Custom Plugin: Develop a custom plugin to enable TCP communication between the Appium server and the AltTester server (you can handle it in your java code also)
  9. Write Tests: Write a Test. Use Appium Inspector or AltTester Desktop to fetch the elements
  10. Create SMG: Simulate player moves for the game you want to automate
  11. Connect Devices to Server: Connect all the devices with the Appium Server Machines
  12. Setup Jenkins Pipeline: Set up a Jenkins Pipeline to automate the build and test execution process
  13. Clone Appium Project: Clone the Appium project from the GIT repository for the latest codebase
  14. Execute Tests: Execute tests using “testng.xml” and Maven

That’s All!

Navigating the realm of Game Automation at Hike was an incredible journey. Every step taught us something new, from facing initial hurdles to celebrating eventual successes. We paid meticulous attention to every detail, perfecting auto-triggering, parallel execution, and insightful reporting. This achievement reflects our team’s unwavering dedication and constant pursuit of perfection.

--

--