-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSendAndReceiveMessageTest.java
More file actions
55 lines (44 loc) · 2 KB
/
SendAndReceiveMessageTest.java
File metadata and controls
55 lines (44 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.serverpushexample;
import com.vaadin.testbench.annotations.RunLocally;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.testbench.elements.TextFieldElement;
import com.vaadin.testbench.parallel.Browser;
import com.vaadin.testbench.parallel.ParallelTest;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@RunLocally(Browser.CHROME)
public class SendAndReceiveMessageTest extends ParallelTest {
private static final String RECEIVE_URL = "http://localhost:8080/vaadin-javaee-server-push-example-1.0-SNAPSHOT/receive-message";
private static final String SEND_URL = "http://localhost:8080/vaadin-javaee-server-push-example-1.0-SNAPSHOT/send-message";
/**
* Open the receive message page, wait until the message sent in testSendMessage() appears, check that it
* is the expected message.
*
* @throws InterruptedException
*/
@Test
public void testReceiveMessage() throws InterruptedException {
getDriver().get(RECEIVE_URL);
final String beforeSendMessage = $(LabelElement.class).last().getText();
assertEquals("Received messages", beforeSendMessage);
// sleep to leave time for message processing
Thread.sleep(4000);
final String afterSendMessage = $(LabelElement.class).last().getText();
assertEquals("Message from testSendMessage", afterSendMessage);
}
/**
* Open the send message page, wait until the receive message page is open in testReceiveMessage(), send
* the test message.
*
* @throws InterruptedException
*/
@Test
public void testSendMessage() throws InterruptedException {
getDriver().get(SEND_URL);
$(TextFieldElement.class).first().setValue("Message from testSendMessage");
$(ButtonElement.class).first().click();
final String text = $(LabelElement.class).last().getText();
assertEquals("Sent message 'Message from testSendMessage'", text);
}
}