Jacobvu84 / serenity-pageobject-junit-webdriver

4 stars 1 forks source link

Xác định location của mobile element theo platform #57

Open Jacobvu84 opened 4 years ago

Jacobvu84 commented 4 years ago

package com.jacob.locator;

import org.openqa.selenium.By;

import com.jacob.questions.Platform;

public class MultipleBy {
    private By androidLocator;
    private By iosLocator;

    public MultipleBy android(By locator) {
        this.androidLocator = locator;
        return this;
    }

    public MultipleBy ios(By locator) {
        this.iosLocator = locator;
        return this;
    }

    public By getByPlatform() {
        if (Platform.isIOS()) {
            return iosLocator;
        } else {
            return androidLocator;
        }
    }
}
Jacobvu84 commented 4 years ago

Cách dùng

    private static By MUTE_ICON = new MultipleBy()
            .android(By.id("android:id/notification_off"))
            .ios(By.id("Notifications off"))
            .getByPlatform();

    private static By MENTION_MESSAGE = new MultipleBy()
            .ios(By.id("You were mentioned."))
            .android(By.id("android:id/alerted_message"))
            .getByPlatform();

    private static By MEMBER_COUNT = new MultipleBy()
            .android(By.id("android:id/member_count"))
            .getByPlatform();

    private static By LAST_MESSAGE_TIME = new MultipleBy()
            .ios(By.xpath("//XCUIElementTypeStaticText[contains(@name,':') and string-length(@name) = 5]"))
            .getByPlatform();