17
const INCREMENTS_PER_DISCONNECT = 5;
18
const NUM_DISCONNECTS = 20;
20
describe("websocket reconnects", () => {
22
Cypress.Cookies.defaults({
23
preserve: ["_streamlit_xsrf"],
26
cy.route("PUT", "**/upload_file/**").as("uploadFile");
28
cy.loadApp("http://localhost:3000/");
31
it("retains session state when the websocket connection is dropped and reconnects", () => {
32
let expectedCount = 0;
34
for (let i = 0; i < NUM_DISCONNECTS; i++) {
35
expectedCount += INCREMENTS_PER_DISCONNECT;
37
for (let j = 0; j < INCREMENTS_PER_DISCONNECT; j++) {
38
cy.get(".stButton button").contains("click me!").click();
41
cy.window().then((win) => {
43
win.streamlitDebug.disconnectWebsocket();
48
cy.get("[data-testid='stStatusWidget']").should(
53
cy.get("[data-testid='stStatusWidget']").should("not.exist");
55
cy.get(".stMarkdown").contains(`count: ${expectedCount}`);
59
it("retains uploaded files when the websocket connection is dropped and reconnects", () => {
60
const fileName1 = "file1.txt";
61
const uploaderIndex = 0;
63
cy.fixture(fileName1).then((file1) => {
65
"[data-testid='stFileUploaderDropzone']",
71
mimeType: "text/plain",
75
subjectType: "drag-n-drop",
76
events: ["dragenter", "drop"],
80
cy.wait("@uploadFile");
85
cy.get(".stFileUploaderFileName").should("have.text", fileName1);
86
cy.getIndexed("[data-testid='stText']", uploaderIndex).should(
91
cy.window().then((win) => {
93
win.streamlitDebug.disconnectWebsocket();
98
cy.get("[data-testid='stStatusWidget']").should(
103
cy.get("[data-testid='stStatusWidget']").should("not.exist");
106
cy.getIndexed("[data-testid='stText']", uploaderIndex).should(
114
"retains captured pictures when the websocket connection is dropped and reconnects",
115
{ retries: { runMode: 1 } },
119
const timeout = 30000;
121
cy.get("[data-testid='stCameraInputButton']", { timeout })
122
.should("have.length", 1)
125
.should("not.be.disabled")
126
.contains("Take Photo")
129
cy.wait("@uploadFile", { timeout });
131
cy.get("img").should("have.length.at.least", 2);
133
cy.get("[data-testid='stImage']", { timeout }).should(
134
"have.length.at.least",
138
cy.window().then((win) => {
140
win.streamlitDebug.disconnectWebsocket();
145
cy.get("[data-testid='stStatusWidget']").should(
150
cy.get("[data-testid='stStatusWidget']").should("not.exist");
153
cy.get("[data-testid='stImage']").should("have.length.at.least", 1);