@@ -20,6 +20,8 @@ const output = '#output'
20
20
const listeningAddresses = '#listening-addresses'
21
21
const subscribeInput = '#subscribe-topic-input'
22
22
const subscribeBtn = '#subscribe-topic-button'
23
+ const topicPeers = '#topic-peers'
24
+ const peerId = '#peer-id'
23
25
24
26
let url
25
27
@@ -73,6 +75,10 @@ test.describe('pubsub browser example:', () => {
73
75
const pageB = await context . newPage ( )
74
76
await pageB . goto ( url )
75
77
78
+ // load page peer ids
79
+ const pageAPeerId = await pageA . textContent ( peerId )
80
+ const pageBPeerId = await pageB . textContent ( peerId )
81
+
76
82
// connect the first page to the relay
77
83
const webRTCAddressA = await dialRelay ( pageA , relayNodeAddr )
78
84
@@ -88,6 +94,10 @@ test.describe('pubsub browser example:', () => {
88
94
await subscribeToTopic ( pageA , topicName )
89
95
await subscribeToTopic ( pageB , topicName )
90
96
97
+ // wait for peers to appear in topic peers
98
+ await waitForTopicPeers ( pageA , pageBPeerId )
99
+ await waitForTopicPeers ( pageB , pageAPeerId )
100
+
91
101
// send a message from one to the other
92
102
await sendMessage ( pageA , 'hello A' , pageB )
93
103
} )
@@ -103,6 +113,11 @@ async function subscribeToTopic (page, topic) {
103
113
await expect ( outputLocator ) . toContainText ( `Subscribing to '${ topic } '` )
104
114
}
105
115
116
+ async function waitForTopicPeers ( page , otherPeer ) {
117
+ const outputLocator = page . locator ( topicPeers )
118
+ await expect ( outputLocator ) . toContainText ( otherPeer )
119
+ }
120
+
106
121
async function sendMessage ( pageA , message , pageB ) {
107
122
// subscribe to the topic
108
123
await pageA . fill ( sendMessageInput , message )
0 commit comments