Appium 中用於混合應用程序的多個屏幕截圖 (Multiple Screenshots in Appium for Hybrid Apps)


問題描述

Appium 中用於混合應用程序的多個屏幕截圖 (Multiple Screenshots in Appium for Hybrid Apps)

我一直在 Appium 中使用屏幕截圖[public void getScreenshot(){...}] 測試失敗並啟動。我想為我的套件中的每個 findElement() 調用相同的方法。我嘗試這樣做:

創建自定義驅動程序為:

public class CustomDriver extends AppiumDriver{
        public WebElement scrollToExact(String element) {   
            WebElement x = null;
            return x;
        }

        public WebElement scrollTo(String element){
            WebElement y = null;
            return y;
        }

        @Override
        public List<WebElement> findElements(By by) {
            try {
                getScreenshot();
            }
            catch (IOException iox){
                System.out.println(iox.getMessage());
            }
            return by.findElements(this);
        }

        @Override
        public WebElement findElement(By by) {
            try {
                getScreenshot();
            } 
            catch(IOException iox){
                System.out.println(iox.getMessage());
            }
            return by.findElement(this);
        }
}

使用此驅動程序創建測試套件。

Q1。雖然這對我來說很好,但是當我將上下文切換到 Webview 時,我的驅動程序不會響應在該上下文中查找元素。我在這裡跟進有什麼問題嗎?[如果需要,會提供詳細信息,自己不確定。]

Q2. 在我的套件中為每個 findElement() 調用獲取屏幕截圖,我缺少什麼更簡單的方法嗎?


參考解法

方法 1:

In my experience screenshots work only in the NATIVE_APP context, so if you are in a WebView context you've got to switch to the native context and then switch back, something like:

    @Override
    public List<WebElement> findElements(By by) {
        String originalContext = getContext();
        if ("NATIVE_APP".equals(originalContext)) {
            originalContext = null; // no need to switch
        } else {
            context("NATIVE_APP");
        }
        try {
            getScreenshot(); // Before screenshot
            return super.findElements(by);
        } finally {                
            if (originalContext!=null) {
                context(originaContext);
            }
        }
    }

(by NamanPavel Vlasov)

參考文件

  1. Multiple Screenshots in Appium for Hybrid Apps (CC BY‑SA 2.5/3.0/4.0)

#screenshot #appium #java #overriding






相關問題

沒有 iPhone,如何使用 XCode 截屏? (Without iPhone, how to take screenshot with XCode?)

mapViewDidFinishLoadingMap:調用過早 (mapViewDidFinishLoadingMap: called too early)

屏幕截圖上的窗口沒有消失 (Window not disappearing on Screenshot)

Appium 中用於混合應用程序的多個屏幕截圖 (Multiple Screenshots in Appium for Hybrid Apps)

在Linux上通過Python腳本拍攝屏幕截圖 (Take a screenshot via a Python script on Linux)

如何使用服務器端腳本生成網頁的屏幕截圖? (How can I generate a screenshot of a webpage using a server-side script?)

如何使用 ruby 和 unix 服務器截取網頁截圖? (How do I take screenshots of web pages using ruby and a unix server?)

使用 jquery 生成網站的屏幕截圖 (generating a screenshot of a website using jquery)

畫面區域的選擇 (Selection of screen area)

使用 PHP 的網頁截圖? (Web Page Screenshots with PHP?)

iPhone:如何在使用 3d 圖層轉換時以編程方式拍攝屏幕截圖 (iPhone: how to take screen shots programmatically when using 3d layer transformations)

防止 VideoView Activity 中的視頻屏幕截圖 - Android (Prevent Video screen capture in VideoView Activity - Android)







留言討論