Home  >  Article  >  Java  >  Appium With Java: A Comprehensive Guide

Appium With Java: A Comprehensive Guide

WBOY
WBOYOriginal
2024-09-04 16:40:02763browse

Are you just starting with Appium Java mobile automation testing? You’re in the right place! This blog is your guide to crafting your inaugural test case. We’ll guide you through setting up your environment, mastering fundamental Appium commands, and automating a simple action on your mobile app. Prepare to embark on your appium mobile testing journey, step by step!

If you haven’t already, feel free to explore our Appium Setup blog post, where we cover Appium setup and basic command navigation. It’s an excellent resource to jumpstart your appium testing adventure! Take a look to kick off your learning! With that groundwork laid, let’s proceed to construct your first test case!

Create project in IntelliJ with maven build systems

  • Maven is an open-source build automation and project management tool that is based on POM (project object model).
  • It uses a project object model (POM) file to describe the project structure, dependencies, and build configurations.
  • It is used for projects build, dependency management and documentation.
  • It’s written in Java and can also be used to create projects written in other languages, such as C#, Scala, and Ruby.
  • Apache Maven 3.9.6 is the latest release. It is the recommended version for all users.

We can build a Maven project in IntelliJ by doing the following

  1. Open IntelliJ IDE
  2. Click on the Main Menu
  3. Select File > New > Project
  4. In New Project Popup window, provide a project name
  5. Select Maven as build System
  6. Click on the create button.

Appium With Java: A Comprehensive Guide

After create a project with Maven build system, pom.xml file will automatically generated under project structure

Appium With Java: A Comprehensive Guide

Pom.xml file will look like the below

Appium With Java: A Comprehensive Guide

  • In order to create our first test case, we would need the following dependency
  1. java-client
  2. testng
  • Add below Appium Java Client dependency in pom.xml file. Take the latest dependencies from this [URL](https://mvnrepository.com/).

Appium With Java: A Comprehensive Guide

  • After adding the dependencies, follow the below steps to download it to the local computer
  1. Save the pom.xml and update the Maven Project by right-clicking on the project and updating the Project inside Maven.
  2. After saving the project, all the dependencies start downloading from the Maven Repository to the local computer.
  3. All the dependencies are downloaded to the C drive under the m2 folder.
  4. Before downloading the dependencies, Maven first verifies whether these dependencies are already present in the m2 folder or not. If yes, then Maven directly takes it from there, else Maven downloads it.
  5. As appium-java dependency we can add more dependencies in pom.xml as per our need.

Configure the TestNG dependency in pom.xml

  • When working on Java Selenium projects, the TestNG dependency is used to integrate the TestNG testing framework into the project.

What is TestNG Framework?

  • TestNG is an open-source test automation framework for Java. TestNG provides advanced features such as annotations, data-driven testing, test sequencing, and parallel testing to help you organize and execute your Selenium tests more efficiently and effectively.

Some of the benefits of using TestNG in appium mobile app testing:

  • Group test cases into logical units, making managing and maintaining your test suite easier.
  • Run tests in parallel, significantly reducing the time it takes to execute your test suite.
  • TestNG provides a wide range of annotations that you can use to customize your tests, such as Test, @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest, @BeforeMethod, and @AfterMethod.
  • It supports data-driven testing, allowing you to run the same test case with multiple test data sets.
  • Better reporting and logging features than other testing frameworks make identifying and debugging issues in your tests easier.
  • To include the TestNG dependency in your project configuration file pom.xml, you need to add the following snippet within the section of the node

Appium With Java: A Comprehensive Guide

Start the appium server from the cmd by writing appium.
Start the emulator and appium inspector as explained in our previous blog.
In IntelliJ, Open the folder src/main/java and create a new java class file within it and write our first test as per below.

Let’s understand our first test case

  • Desired Capabilities : Which is a concept explained in our previous appium blog .It is a type of key-value combination information, which tells the Appium about our device, what kind of device to use (Android), how to control the app (UiAutomator2), and where to find the app. These capabilities are essential for establishing a connection with the emulator or physical device during test automation.
  • Connect and Launch: We connect to the Appium server and use it to open the app on the device. We also set a short wait time in case the app takes a moment to load.
  • Play the User: The code acts like a user by finding buttons, text fields, and other elements on the screen. It then enters text, clicks buttons, and scrolls through lists just like a real person would.
  • Check the Work: Finally, the code makes sure everything works as planned. It grabs the title of the first product on the list and compares it to what we expect (like “Air Jordan 4 Retro”). If they don’t match, it means something went wrong, and the test fails.
  • Below is a screenshot of the application page for which we wrote the above test script using appium mobile app testing with Java.

Appium With Java: A Comprehensive Guide

  • Executing the appium test script : Once the code is written, you can execute/run it by right clicking on the test and clicking on ‘Run’. It will launch the mobile app on the connected device or emulator and perform the actions specified in the test script. Once the execution is complete you can see the execution logs in the console as shown below

Appium With Java: A Comprehensive Guide

結論

Appium と Java は連携して、モバイル アプリのテストを自動化し、開発プロセス全体を通じて時間とリソースを節約するための強力なソリューションを作成します。これにより、高品質のアプリを配信できるようになります。このガイドでは、環境を設定し、最初のテストを作成することで、作業を開始する準備ができています。しかし、これはほんの始まりに過ぎません。さらに詳しく調べると、Appium は他のツールと統合してさまざまな種類のアプリをテストできるため、堅牢なテスト プロセスを構築できます。 Appium と Java を採用することで、反復的なタスクを自動化し、バグを早期に発見し、優れたモバイル アプリを自信を持って配信できます。それでは、Appium と Java のテストの冒険を今すぐ始めましょう!

Jignect を使用してこれらの強力なツールをさらに習得するには、練習と探索を続けてください。

当社の細心の注意を払ったアプローチと最先端のソリューションが、どのように品質とパフォーマンスを新たな高みに引き上げたかをご覧ください。優れたソフトウェア テストの世界への旅を始めましょう。詳細については、「ツールとテクノロジーと QA サービス」を参照してください。

当社が提供する素晴らしいサービスについて詳しく知りたい場合は、必ずお問い合わせください。

テストを楽しんでください! ?

The above is the detailed content of Appium With Java: A Comprehensive Guide. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn