我的Selenium框架可以使用传入的消息吗

我的Selenium框架可以使用传入的消息吗

本文介绍了我的Selenium框架可以使用传入的消息吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我的Selenium框架如何使位于消息队列中的消息出队.我已经构建了一个应用程序,用于将包含k/v对的JSON字符串发送到消息队列.

I would like to know how my Selenium framework can dequeue a message sitting in a message queue. I have built an application to send a JSON string containing k/v pairs to a message queue.

我的体系结构如下,并包含单独的应用程序:

My architecture is as follows and separate apps:

  1. JSP Web应用程序存在接受参数,从而产生JSON字符串
  2. 消息发件人存在,并接收JSON字符串并将其发布到队列中
  3. 消息使用者存在并使用消息.它基本上只是坐在这里
  4. 存在一个Selenium Java框架,但我想处理这些消息,并且对于每条消息,它将解释k/v对并启动脚本.

我想使用队列中已有的消息并在selenium框架中处理这些消息,我该如何实现?

I would like to use the messages already in the queue and process these messages within the selenium framework, how can I achieve this?

我将感谢您的帮助.我已经用代码编辑了问题

I will appreciate the help. I have edited the question with the code

public class MessageSender {
public static void main(String[] args) throws IOException {

    SingleNumberLogin generateLogin = new SingleNumberLogin();
    //function call to build the JSON object
    String jsonQueue = generateLogin.buildJASONObject();

    ConnectionFactory conFactory = new ConnectionFactory();
    try {
        Connection connInterface =  conFactory.newConnection();
        Channel mqChannel = connInterface.createChannel();
        mqChannel.queueDeclare("MyQueue",false,false,false,null);
        //Just assigning json to another string, then publish the message
        String myMessage = jsonQueue;

        mqChannel.basicPublish("","MyQueue",false ,false, null,myMessage.getBytes());
    }catch (
            IOException | TimeoutException e)
    {
        System.out.println(e.getStackTrace());
    }
    conFactory.setUsername("guest");
    conFactory.setPassword("guest");
    conFactory.setVirtualHost("/");
    conFactory.setHost("localhost");
    conFactory.setPort(5672);
}

}

    @BeforeTest
public static void initializeTestBaseSetup() throws Exception, IOException, TimeoutException {
    ConnectionFactory conFactory = new ConnectionFactory();
    Connection connInterface =  conFactory.newConnection();
    Channel mqChannel = connInterface.createChannel();
    mqChannel.queueDeclare("MyQueue",false,false,false,null);
    mqChannel.basicConsume("MyQueue", true, (consumerTag, message) -> {
        //convert to byte array
        String m = new String (message.getBody(), "UTF-8");
        System.out.println("Message received" + m);
    }, consumerTag -> {

    });
}
JSON Message received 2020-08-28T20:39:30.845{
  "NUMBER": "0000011111",
  "Type": "BAU",
  "User": "MyUser ",
  "Email": "[email protected]",
}

在隔离测试中,它工作得很好,我的意思是我发送了消息并检查使用者是否收到消息,将使用者代码添加到我的框架中就是我所困的地方.

When tested in isolation, it works perfectly fine, what I mean is that I send the message and check that the consumer receives it, adding the consumer code to my framework is where i am stuck.

推荐答案

我建议您不要考虑作为"框架"的东西. -将其视为" java 框架".

I would suggest you don't think about what you have as a "selenium framework" - think of it as a "java framework".

Selenium是一组库,可让您在GUI级别上自动化Web浏览器.该框架是经过编码的解决方案,可帮助您轻松创建和管理测试套件-不必局限于硒,而且硒已经仅仅是其组成部分之一.

Selenium is a set of libraries that allow you automate the web browser at a GUI level. The framework is the coded solution to facilitate creation and management of your test suite - it doesn't have to be limited to selenium and chances that's already just one of its components.

尝试直接回答您的问题:

Trying to answer your question directly:

  • SELENIUM无法阅读邮件
  • JAVA可以阅读消息

如果Rabbitmq具有Web前端,则您也许可以使用硒,但这不是非常有效或合乎逻辑的解决方案.

If your rabbitmq has a web front end then you may be able to use selenium for it, but this isn't a very efficient or a logical solution.

您可能要考虑的事情以及我会做的是扩展您的框架,以使用Rabbitmq库根据需要处理消息.这些库是为此任务而设计的.

What you might want to consider, and what i would do, is extending your framework to use the rabbitmq libraries to process messages as you need. These libraries are designed for this task.

您说:

我理解这意味着消息是测试的先决条件数据.如果您想在测试前阅读消息的值,则可以:

I understand this to mean that the messages are the pre-req data for the tests. If you want to read the values of a message before the test you can either:

  • 将获取/读取放入通用的@Before方法
  • 或者如果它是每个测试用例的特定消息,请将其添加到测试的开始.

您正在使用Java进行工作,因此您可以真正做任何想做的事情.

You're working in java so you can do whatever you want really.

为使您入门,rabbitmq教程从此处开始.

To get you started, the rabbitmq tutorial starts here.

这是一个从队列中读取消息的世界示例:

This is there hello world example for reading messages from the queue:

public class Recv {

  private final static String QUEUE_NAME = "hello";

  public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

  }
}

这篇关于我的Selenium框架可以使用传入的消息吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 05:34