聊天信使app的自动化

时间:2018-06-07 16:04:39

标签: xmpp appium messenger

我想自动化一个像Whatsapp一样的官方应用程序。要测试它,要求是同时打开两个设备,然后使用一个设备发送消息/图像或创建一个组。然后,同时在其他设备上检查是否所有操作都成功完成(收到的消息,作为组成员添加)。 申请基于XMPP。

任何人都可以建议如何继续以及我们可以使用哪种工具来自动化功能?

1 个答案:

答案 0 :(得分:0)

您可以实施自己的自定义Stanza,例如Extension 就像我对Seen状态的消息一样。

首先,像Seen一样创建像Seen这样实现PacketExtension的类。

public class Seen implements PacketExtension, Parcelable {
    public static final String NAMESPACE = "jabber:client";
    public static final String ELEMENT_NAME = "seen";
    public static final String TAG_NAME_NAME = "from";

    private String from;

    public Seen() {}

    public Seen(Parcel parcel) {
        from = parcel.readString();
    }

    public String getName() {
        return name;
    }

    @Override
    public String getElementName() {
        return ELEMENT_NAME;
    }

    @Override
    public String getNamespace() {
        return NAMESPACE;
    }

    @Override
    public CharSequence toXML() {
        return String.format("<seen xmlns='jabber:client'><from>%s</from></seen>", from);
    }

    public String getSeen() {
        return seen;
    }


    public void setSeen(String seen) {
        this.seen = seen;
    }    

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeString(address);
        dest.writeDouble(latitude);
        dest.writeDouble(longitude);
    }

    public static final Parcelable.Creator<Seen> CREATOR = new Creator<Seen>() {

        @Override
        public Seen createFromParcel(Parcel source) {
            return new Seen(source);
        }

        @Override
        public Seen[] newArray(int size) {
            return new Seen[size];
        }
    };
}

ProviderManager中添加第二个扩展程序,如:

ProviderManager.addExtensionProvider(Seen.ELEMENT_NAME, Seen.NAMESPACE, new SeenMessageProvider());

第三,你必须拥有MessagePacketListener来实现PacketListener,当你收到你的消息节时,你会检查它是否是覆盖方法processPacket中的instance of Seen类:

@Override
    public void processPacket(Packet packet) {
        Message msg = (Message)packet;      

        Collection<PacketExtension> extensions = msg.getExtensions();
        if (extensions != null) {
            Iterator<PacketExtension> iterator = extensions.iterator();
            if (iterator.hasNext()) {
                PacketExtension extension = iterator.next();
                if (extension instanceof Seen) {
                    //Do sth
                }
            }
        }
    }

最后,当您使用方法发送消息时,您会发送以下内容:

Seen seen = new Seen();
seen.setFrom("FromUser");
PacketExtension packetExtension = seen;
sendChatMessage(to, body, packetExtension);

public void sendChatMessage(String to, String body, PacketExtension packetExtension) throws SmackInvocationException {
            Message message = new Message(to, Message.Type.chat);
            message.setBody(body);
            if (packetExtension != null) {
                message.addExtension(packetExtension);
            }
            try {
                con.sendPacket(message);
            } catch (NotConnectedException e) {
                throw new SmackInvocationException(e);
            }
        }