Automate update entries in log file using avd and appium

I want to create a txt file which stores the details against a certain section in my app. The app is open in Emulator. It copies the entries and pastes it but only one iteration is done. I have to run the test over and over to find any bugs in this section. I am attaching my code below.

package Test.Appium;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;

public class Test1 {

    @SuppressWarnings("unused")
    @Test
    public void LogDateTest() throws URISyntaxException, InterruptedException, IOException {

        UiAutomator2Options options = new UiAutomator2Options();
        options.setDeviceName("Emulator"); // emulator

        AndroidDriver driver = new AndroidDriver(new URI("http://000.0.0.0:4723/").toURL(), options);//add ur ip

        try {
            WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));

            // Locate the SE app which is already open
            WebElement app = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("")));//xpath of my app
            app.click();

            // Locate the "Last updated" section and get the time and date
            WebElement lastUpdatedElement = wait.until(ExpectedConditions.presenceOfElementLocated(By.id(");//id of the section that im storing in my txt file
            if (lastUpdatedElement != null) {
                String lastUpdatedText = lastUpdatedElement.getText();
                System.out.println("Last Updated: " + lastUpdatedText);

                // Log the time and date to a file
                logLastUpdated(lastUpdatedText);
            } else {
                System.out.println("Element not found: ");
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // Close driver after test execution
            if (driver != null) {
                driver.quit();
            }
        }
    }

    // Method to log the last updated information to a file
    public void logLastUpdated(String lastUpdated) throws IOException {
        String logFilePath = "";//txt file location
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(logFilePath, true))) {
            writer.write(lastUpdated);
            writer.newLine();
            System.out.println("Logged: " + lastUpdated);
        } catch (IOException e) {
            e.printStackTrace();
            `System.out.println("Failed to log data to file: " + e.getMessage());
        }
    }
}

I am expecting to only run the code once and it stores at least 60 entries. I want the code to run for a minimum of 60 mins. The scenario is to store the data of this specific section in the txt file. It should run for an hour and store the values after each minute. I want to identify if there is any missing values or if there is an error in updating the values.

New contributor

leftcode is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật