How to use getWrappedElement method of io.appium.java_client.pagefactory.Widget class

Best io.appium code snippet using io.appium.java_client.pagefactory.Widget.getWrappedElement

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

NYPostPage.java

Source: NYPostPage.java Github

copy
1package pages;
2
3import utils.TestUtils;
4import io.appium.java_client.AppiumDriver;
5import io.appium.java_client.MobileElement;
6import io.appium.java_client.android.AndroidElement;
7import io.appium.java_client.pagefactory.AndroidFindBy;
8import io.appium.java_client.pagefactory.AppiumFieldDecorator;
9import io.appium.java_client.pagefactory.iOSXCUITFindBy;
10import org.openqa.selenium.support.ui.ExpectedConditions;
11import org.openqa.selenium.support.ui.WebDriverWait;
12import org.openqa.selenium.SearchContext;
13import org.openqa.selenium.WebDriver;
14import org.openqa.selenium.WebElement;
15import org.openqa.selenium.support.PageFactory;
16
17import base.BaseTest;
18
19public class NYPostPage extends BaseTest {
20
21	// private ThreadLocal<AppiumDriver> driver2;
22	public WebDriverWait wait;
23
24	
25	/*
26	 * public NYPostPage(SearchContext driver) { this.driver =
27	 * (ThreadLocal<AppiumDriver<WebElement>>) driver; PageFactory.initElements(new
28	 * AppiumFieldDecorator(driver), this); }
29	 */
30	 
31	//laskhmi commented below line
32	//TestUtils utils = new TestUtils();
33
34	
35	  public NYPostPage(ThreadLocal<AppiumDriver<WebElement>> driver) {
36	  //base.BaseTest.driver = driver; 
37	  PageFactory.initElements(new
38	  AppiumFieldDecorator((SearchContext) driver), this); 
39	  }
40	 
41
42	@AndroidFindBy(className = "android.widget.ProgressBar")
43	@iOSXCUITFindBy(xpath = "//XCUIElementTypeOther[@name=\"test-Toggle\"]/parent::*[1]/preceding-sibling::*[1]")
44	private static MobileElement loadingIcon;
45
46	@AndroidFindBy(className = "android.view.View")
47	@iOSXCUITFindBy(xpath = "//XCUIElementTypeOther...etc")
48	private MobileElement saveBtn;
49
50	@AndroidFindBy(xpath = "//android.widget.Button")
51	private static MobileElement continueBtn;
52
53
54	BaseTest BaseTest;
55
56	public static void loadingIcon() throws InterruptedException, NullPointerException {
57		try {
58			while (loadingIcon.isDisplayed()) {
59				Thread.sleep(500);
60			}
61		} catch (Exception e) {
62			System.out.println("The element disappeared");
63		}
64	}
65
66	public void saveBtnClick() {
67		saveBtn.click();
68	}
69
70	public void continueBtnClick() {
71		// try {
72		//((AndroidElement) getWrappedElement()).tap(1, 1500);
73		wait = new WebDriverWait((WebDriver) driver, 10);
74		wait.until(ExpectedConditions.visibilityOf(continueBtn));
75		continueBtn.click();
76		// } catch (Exception e) {
77		// System.out.println(e);
78		// }
79		// BaseTest.click(continueBtn);
80		// findElement(By.xpath("//android.widget.ImageButton[@content-desc='Navigate
81		// up']")).click();
82	}
83
84	
85
86}
87
Full Screen

SearchScreen.java

Source: SearchScreen.java Github

copy
1package com.google.android.youtube.automation.screens.ios;
2
3import com.google.android.youtube.automation.screens.widget.SearchListVideoInformationWidget;
4import com.google.android.youtube.automation.screens.widget.SearchListWidget;
5import com.google.android.youtube.automation.util.annottation.Screen;
6import io.appium.java_client.AppiumDriver;
7import io.appium.java_client.MobileElement;
8import io.appium.java_client.pagefactory.AndroidFindBy;
9import io.appium.java_client.pagefactory.WithTimeout;
10import io.qameta.allure.Step;
11import org.springframework.beans.factory.annotation.Autowired;
12
13import java.util.List;
14import java.util.concurrent.TimeUnit;
15
16/**
17 * @author Carmelo Buelvas
18 * @since 1.0
19 */
20@Screen
21public class SearchScreen extends com.google.android.youtube.automation.pageobject.Screen {
22
23    @AndroidFindBy(accessibility = "Navegar hacia arriba")
24    private MobileElement navigationBackButton;
25
26    @AndroidFindBy(id = ID + "search_edit_text")
27    private MobileElement searchBox;
28
29    @AndroidFindBy(accessibility = "Búsqueda por voz")
30    private MobileElement voiceSearchButton;
31
32    @AndroidFindBy(accessibility = "Borrar")
33    private MobileElement clearButton;
34
35    @AndroidFindBy(accessibility = "Filtrar")
36    private MobileElement filterButton;
37
38    @WithTimeout(time = 30, unit = TimeUnit.SECONDS)
39    private List<SearchListWidget> searchListWidgets;
40
41    @WithTimeout(time = 60, unit = TimeUnit.SECONDS)
42    private List<SearchListVideoInformationWidget> searchListVideoInformationWidgets;
43
44    /**
45     * @param appiumDriver
46     */
47    @Autowired
48    public SearchScreen(AppiumDriver<? extends MobileElement> appiumDriver) {
49        super(appiumDriver);
50    }
51
52    @Step("Type video name")
53    public SearchScreen typeVideoName(String videoName) {
54        type(searchBox, videoName);
55        return this;
56    }
57
58    @Step("Select result")
59    public SearchScreen selectSearchResult(String NameVideo) {
60        searchListWidgets.stream()
61                .filter(searchListWidget -> searchListWidget.getTextLastSearch().getText().equals(NameVideo.toLowerCase()))
62                .findFirst()
63                .ifPresent(searchListWidget -> searchListWidget.getWrappedElement().click());
64        return this;
65    }
66
67    @Step("Select result")
68    public VideoScreen selectSearchResultVideo(String nameChannel) {
69        searchListVideoInformationWidgets.stream()
70                .filter(widget -> widget.getAuthor().getText().equals(nameChannel))
71                .findFirst()
72                .ifPresent(widget -> widget.getWrappedElement().click());
73        return new VideoScreen(getDriver());
74    }
75
76    /**
77     * @return <code>Boolean.TRUE</code> if the search result is valid;
78     * <code>Boolean.FALSE</code> otherwise
79     */
80    @Step("Validate results")
81    public Boolean isValidSearchResult() {
82        return searchListWidgets.stream()
83                .findFirst()
84                .map(searchListWidget -> searchListWidget.getSearchTypeIcon().isDisplayed()
85                        && searchListWidget.getTextLastSearch().isDisplayed()
86                        && searchListWidget.getEditSuggestionButton().isDisplayed())
87                .orElse(Boolean.FALSE);
88    }
89
90    /**
91     * @return <code>Boolean.TRUE</code> if the search result video is valid;
92     * <code>Boolean.FALSE</code> otherwise
93     */
94    @Step("Validate results")
95    public Boolean isValidSearchResultVideo(String nameChannel) {
96        return searchListVideoInformationWidgets.stream()
97                .findFirst()
98                .map(widget -> widget.getAuthor().getText().equals(nameChannel))
99                .orElse(Boolean.FALSE);
100    }
101}
102
Full Screen

DefaultStubWidget.java

Source: DefaultStubWidget.java Github

copy
1package io.appium.java_client.pagefactory_tests.widget.tests;
2
3import com.google.common.collect.ImmutableList;
4
5import io.appium.java_client.pagefactory.Widget;
6import org.openqa.selenium.WebElement;
7
8import java.util.List;
9
10public class DefaultStubWidget extends Widget {
11    protected DefaultStubWidget(WebElement element) {
12        super(element);
13    }
14
15    public <T extends Widget> T getSubWidget() {
16        return null;
17    }
18
19    public <T extends Widget> List<T> getSubWidgets() {
20        return ImmutableList.of();
21    }
22
23    @Override
24    public String toString() {
25        return getWrappedElement().toString();
26    }
27}
28
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger getWrappedElement code on LambdaTest Cloud Grid

Execute automation tests with getWrappedElement on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)