Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 4074b39

Browse files
committed
Wait for text to be ready the proper way
1 parent 7c76ac3 commit 4074b39

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

runestone/activecode/test/test_activecode.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def test_hello(self):
3131
self.assertIsNotNone(rb)
3232
rb.click()
3333
time.sleep(0.5)
34+
wait = WebDriverWait(self.driver, 10)
35+
wait.until(
36+
EC.text_to_be_present_in_element((By.ID, "test1_stdout"), "Hello")
37+
)
3438
output = t1.find_element_by_class_name("ac_output")
3539
self.assertEqual(output.text.strip(), "Hello World")
3640

@@ -54,7 +58,9 @@ def test_hidden(self):
5458
rb = t1.find_element_by_class_name("run-button")
5559
self.assertIsNotNone(rb)
5660
rb.click()
57-
time.sleep(0.5)
61+
wait.until(
62+
EC.text_to_be_present_in_element((By.ID, "testprefixcode_stdout"), "My")
63+
)
5864
output = t1.find_element_by_class_name("ac_output")
5965
self.assertIn("My Code", output.text.strip())
6066
self.assertIn("hidden code", output.text.strip())
@@ -173,7 +179,10 @@ def test_sql_activecode(self):
173179
rb = t2.find_element_by_class_name("run-button")
174180
self.assertIsNotNone(rb)
175181
rb.click()
176-
time.sleep(0.5)
182+
wait = WebDriverWait(self.driver, 10)
183+
wait.until(
184+
EC.text_to_be_present_in_element((By.ID, "sql1_stdout"), "You")
185+
)
177186
res = self.driver.find_element_by_id("sql1_sql_out")
178187
self.assertIsNotNone(res)
179188
out = self.driver.find_element_by_id("sql1_stdout")
@@ -195,6 +204,10 @@ def test_readfiles(self):
195204
rb = t2.find_element_by_class_name("run-button")
196205
self.assertIsNotNone(rb)
197206
rb.click()
207+
wait = WebDriverWait(self.driver, 10)
208+
wait.until(
209+
EC.text_to_be_present_in_element((By.ID, "ac9_13_1_stdout"), "Lind")
210+
)
198211
out = t2.find_element_by_id("ac9_13_1_stdout")
199212
self.assertIsNotNone(out)
200213
self.assertTrue("Lindenau" in out.text)
@@ -208,7 +221,10 @@ def test_altair(self):
208221
rb.click()
209222
out = t2.find_element_by_id("alt_kiva_bar1_stdout")
210223
self.assertIsNotNone(out)
211-
time.sleep(.5)
224+
wait = WebDriverWait(self.driver, 10)
225+
wait.until(
226+
EC.text_to_be_present_in_element((By.ID, "alt_kiva_bar1_stdout"), "mark")
227+
)
212228
self.assertIn("mark = bar", out.text)
213229
self.assertIn("{'field': 'customer', 'type': 'nominal'}", out.text)
214230
can = t2.find_element_by_tag_name("canvas")
@@ -221,9 +237,12 @@ def test_image(self):
221237
rb = t2.find_element_by_class_name("run-button")
222238
self.assertIsNotNone(rb)
223239
rb.click()
240+
wait = WebDriverWait(self.driver, 10)
241+
wait.until(
242+
EC.text_to_be_present_in_element((By.ID, "ac14_7_2_stdout"), "400")
243+
)
224244
out = t2.find_element_by_id("ac14_7_2_stdout")
225245
self.assertIsNotNone(out)
226-
time.sleep(1)
227246
self.assertTrue("400" in out.text)
228247
self.assertTrue("244" in out.text)
229248
self.assertTrue(("165 161 158" in out.text) or ("165 162 157" in out.text))

0 commit comments

Comments
 (0)