1+ from playwright .sync_api import expect , Page
2+ import toml
3+ import pytest
4+ import random
5+
6+ data = toml .load ("config/config.toml" )
7+
8+ titleNum = random .randint (0 , 1000 )
9+
10+
11+ # This allows us to autologin with a cookie in all tests instead of having to login each time
12+ @pytest .fixture (scope = "session" )
13+ def browser_context_args (browser_context_args ):
14+ """ """
15+ browser_context_args .update (storage_state = "config/state.json" ,)
16+ return browser_context_args
17+
18+
19+ def test_competition_upload (page : Page ):
20+ page .goto ("http://localhost/" )
21+ page .get_by_role ("link" , name = " Benchmarks/Competitions" ).click ()
22+ page .get_by_role ("link" , name = " Upload" ).click ()
23+ with page .expect_file_chooser () as fc_info :
24+ page .get_by_role ("button" , name = "" ).click ()
25+ file_chooser = fc_info .value
26+ file_chooser .set_files ("test_files/competitions/competition.zip" )
27+ expect (page .get_by_text ("Competition created!" )).to_be_visible ()
28+
29+
30+ def task_creation (page ):
31+ page .goto ("http://localhost/" )
32+ page .get_by_text ("codabench Admin management" ).click ()
33+ page .get_by_role ("link" , name = " Resources" ).click ()
34+ page .get_by_text ("Datasets and programs" ).first .click ()
35+ page .get_by_role ("button" , name = " Add Dataset/Program" ).click ()
36+ page .get_by_role ("textbox" , name = "Name" ).click ()
37+ page .get_by_role ("textbox" , name = "Name" ).fill (str (titleNum ) + "Playwright Scoring Program" )
38+ page .get_by_role ("textbox" , name = "Description" ).click ()
39+ page .get_by_role ("textbox" , name = "Description" ).fill ("Test Dataset Description" )
40+ page .locator (".ui.form > div > .ui" ).click ()
41+ page .get_by_text ("Scoring Program" , exact = True ).nth (5 ).click ()
42+ with page .expect_file_chooser () as fc_info :
43+ page .get_by_role ("button" , name = "" ).click ()
44+ file_chooser = fc_info .value
45+ file_chooser .set_files ("test_files/Task/Scoring Program/scoring_program.zip" )
46+ page .get_by_role ("button" , name = " Upload" ).click ()
47+ page .get_by_text ("Tasks" , exact = True ).click ()
48+ page .get_by_text ("Create Task" ).first .click ()
49+ page .get_by_role ("textbox" , name = "Name" , exact = True ).click ()
50+ page .get_by_role ("textbox" , name = "Name" , exact = True ).fill (str (titleNum ) + "Playwright Task" )
51+ page .get_by_role ("textbox" , name = "Description" ).click ()
52+ page .get_by_role ("textbox" , name = "Description" ).fill ("Test Descirption Task" )
53+ page .get_by_text ("Datasets and programs" ).nth (3 ).click ()
54+ page .locator ("#scoring_program" ).click ()
55+ page .locator ("#scoring_program" ).fill ("test" )
56+ page .locator ("a" ).filter (has_text = str (titleNum ) + "Playwright Scoring Program" ).click ()
57+ page .get_by_text ("Create" , exact = True ).click ()
58+
59+
60+ def test_manual_competition_creation (page : Page ):
61+ task_creation (page )
62+ page .goto ("http://localhost/" )
63+ page .get_by_role ("link" , name = " Benchmarks/Competitions" ).click ()
64+ page .get_by_role ("link" , name = " Create" ).click ()
65+ page .get_by_role ("textbox" ).nth (1 ).click ()
66+ page .get_by_role ("textbox" ).nth (1 ).fill ("Test" )
67+ with page .expect_file_chooser () as fc_info :
68+ page .get_by_role ("button" , name = "" ).click ()
69+ file_chooser = fc_info .value
70+ file_chooser .set_files ("test_files/competition/test_logo.png" )
71+ page .locator (".CodeMirror-scroll" ).first .click ()
72+ page .get_by_role ("application" ).get_by_role ("textbox" ).fill ("on" )
73+ page .get_by_role ("textbox" , name = "Example: codalab/codalab-" ).click ()
74+ page .get_by_role ("textbox" , name = "Example: codalab/codalab-" ).fill ("codalab/codalab-legacy:py37" )
75+ page .get_by_text ("Participation" ).click ()
76+ page .locator ("pre" ).nth (3 ).click ()
77+ page .get_by_role ("application" ).filter (has_text = "|||xxxxxxxxxx 101:" ).get_by_role ("textbox" ).fill ("Test Terms" )
78+ page .locator ("input[name=\" registration_auto_approve\" ]" ).check ()
79+ page .locator ("a" ).filter (has_text = "Pages" ).click ()
80+ page .get_by_role ("button" , name = " Add page" ).click ()
81+ page .get_by_role ("textbox" ).nth (1 ).fill ("Test Title" )
82+ page .locator ("div:nth-child(2) > .EasyMDEContainer > .CodeMirror > .CodeMirror-scroll" ).click ()
83+ page .get_by_role ("application" ).get_by_role ("textbox" ).fill ("Test Content" )
84+ page .get_by_text ("Save" ).nth (1 ).click ()
85+ page .locator ("a" ).filter (has_text = "Phases" ).click ()
86+ page .get_by_role ("button" , name = " Add phase" ).click ()
87+ page .locator ("input[name=\" name\" ]" ).click ()
88+ page .locator ("input[name=\" name\" ]" ).fill (str (titleNum ) + "Playwright Task" )
89+ page .locator ("input[name=\" start_date\" ]" ).click ()
90+ page .get_by_role ("cell" , name = "12" ).click ()
91+ page .locator ("input[name=\" start_time\" ]" ).click ()
92+ page .get_by_role ("cell" , name = "10:" ).click ()
93+ page .get_by_role ("cell" , name = ":00" ).click ()
94+ page .locator ("input[name=\" end_date\" ]" ).click ()
95+ page .locator ("input[name=\" end_date\" ]" ).fill ("" )
96+ page .locator ("div:nth-child(7) > .EasyMDEContainer > .CodeMirror > .CodeMirror-scroll" ).click ()
97+ page .locator (".CodeMirror.cm-s-easymde.CodeMirror-wrap.CodeMirror-focused > div > textarea" ).fill ("Phase" )
98+ page .locator (".ui.search.selection.dropdown.multiple" ).first .click ()
99+ page .locator (".ui.search.selection.dropdown.multiple > .search" ).first .fill (str (titleNum ) + "Playwright Task" )
100+ page .get_by_text (str (titleNum ) + "Playwright Task" ).nth (1 ).click ()
101+ page .get_by_text ("Save" ).nth (3 ).click ()
102+ page .get_by_text ("Leaderboard" , exact = True ).click ()
103+ page .get_by_role ("button" , name = " Add leaderboard" ).click ()
104+ page .locator ("input[name=\" title\" ]" ).click ()
105+ page .locator ("input[name=\" title\" ]" ).fill ("Test title LEaderboard" )
106+ page .locator ("input[name=\" key\" ]" ).click ()
107+ page .locator ("input[name=\" key\" ]" ).fill ("Test Key" )
108+ page .locator (".ui.plus" ).click ()
109+ page .locator ("input[name=\" column_key_0\" ]" ).click ()
110+ page .locator ("input[name=\" column_key_0\" ]" ).fill ("Test Key" )
111+ page .locator ("input[name=\" key\" ]" ).click ()
112+ page .locator ("input[name=\" key\" ]" ).press ("ControlOrMeta+a" )
113+ page .locator ("input[name=\" key\" ]" ).fill ("Key" )
114+ page .locator ("input[name=\" column_key_0\" ]" ).click ()
115+ page .get_by_text ("Save" ).nth (4 ).click ()
116+ page .get_by_role ("button" , name = "Save" ).click ()
117+ expect (page .get_by_text ("Test" , exact = True )).to_be_visible ()
118+ expect (page .get_by_text ("Test Content" )).to_be_visible ()
119+
120+ # TODO Verify a few more items from the created competition
0 commit comments