1- import { Builder , By , until , Key } from "selenium-webdriver" ;
1+ import { Builder , By , until , Key , WebDriver } from "selenium-webdriver" ;
22import * as Chrome from "selenium-webdriver/chrome" ;
33import * as Path from "path" ;
44
@@ -21,24 +21,68 @@ test("Selenium Chrome test", async () => {
2121 await driver . get ( "https://www.youtube.com/watch?v=jNQXAC9IVRw" ) ;
2222 await driver . wait ( until . elementIsVisible ( await driver . findElement ( By . className ( "ytd-video-primary-info-renderer" ) ) ) ) ;
2323
24- const startSegmentButton = await driver . findElement ( By . id ( "startSegmentButton" ) ) ;
25- const cancelSegmentButton = await driver . findElement ( By . id ( "cancelSegmentButton" ) ) ;
26- await driver . executeScript ( "document.querySelector('video').currentTime = 0" ) ;
24+ await createSegment ( driver , "4" , "10.33" , "0:04.000 to 0:10.330" ) ;
2725
28- await startSegmentButton . click ( ) ;
29- await driver . wait ( until . elementIsVisible ( cancelSegmentButton ) ) ;
26+ await editSegments ( driver , 0 , "0:04.000" , "0:10.330" , "5" , "13.211" , "0:05.000 to 0:13.211" , false ) ;
27+ } finally {
28+ await driver . quit ( ) ;
29+ }
30+ } , 100_000 ) ;
31+
32+ async function createSegment ( driver : WebDriver , startTime : string , endTime : string , expectedDisplayedTime : string ) : Promise < void > {
33+ const startSegmentButton = await driver . findElement ( By . id ( "startSegmentButton" ) ) ;
34+ const cancelSegmentButton = await driver . findElement ( By . id ( "cancelSegmentButton" ) ) ;
35+ await driver . executeScript ( "document.querySelector('video').currentTime = " + startTime ) ;
3036
31- await driver . executeScript ( "document.querySelector('video').currentTime = 10.33" ) ;
37+ await startSegmentButton . click ( ) ;
38+ await driver . wait ( until . elementIsVisible ( cancelSegmentButton ) ) ;
3239
33- await startSegmentButton . click ( ) ;
34- await driver . wait ( until . elementIsNotVisible ( cancelSegmentButton ) ) ;
40+ await driver . executeScript ( "document.querySelector('video').currentTime = " + endTime ) ;
3541
42+ await startSegmentButton . click ( ) ;
43+ await driver . wait ( until . elementIsNotVisible ( cancelSegmentButton ) ) ;
44+
45+ const submitButton = await driver . findElement ( By . id ( "submitButton" ) ) ;
46+ await submitButton . click ( ) ;
47+
48+ const sponsorTimeDisplays = await driver . findElements ( By . className ( "sponsorTimeDisplay" ) ) ;
49+ const sponsorTimeDisplay = sponsorTimeDisplays [ sponsorTimeDisplays . length - 1 ] ;
50+ await driver . wait ( until . elementTextIs ( sponsorTimeDisplay , expectedDisplayedTime ) ) ;
51+ }
52+
53+ async function editSegments ( driver : WebDriver , index : number , expectedStartTimeBox : string , expectedEndTimeBox : string ,
54+ startTime : string , endTime : string , expectedDisplayedTime : string , openSubmitBox : boolean ) : Promise < void > {
55+
56+ if ( openSubmitBox ) {
3657 const submitButton = await driver . findElement ( By . id ( "submitButton" ) ) ;
3758 await submitButton . click ( ) ;
38-
39- const sponsorTimeDisplay = await driver . findElement ( By . className ( "sponsorTimeDisplay" ) ) ;
40- await driver . wait ( until . elementTextIs ( sponsorTimeDisplay , "0:00.000 to 0:10.330" ) ) ;
41- } finally {
42- await driver . quit ( ) ;
4359 }
44- } , 100_000 ) ;
60+
61+ let editButton = await driver . findElement ( By . id ( "sponsorTimeEditButtonSubmissionNotice" + index ) ) ;
62+ let sponsorTimeDisplays = await driver . findElements ( By . className ( "sponsorTimeDisplay" ) ) ;
63+ let sponsorTimeDisplay = sponsorTimeDisplays [ index ] ;
64+ await sponsorTimeDisplay . click ( ) ;
65+ // Ensure edit time appears
66+ await driver . findElement ( By . id ( "submittingTime0SubmissionNotice" + index ) ) ;
67+
68+ // Try the edit button too
69+ await editButton . click ( ) ;
70+ await editButton . click ( ) ;
71+
72+ const startTimeBox = await driver . findElement ( By . id ( "submittingTime0SubmissionNotice" + index ) ) ;
73+ expect ( ( await startTimeBox . getAttribute ( "value" ) ) ) . toBe ( expectedStartTimeBox ) ;
74+ await startTimeBox . clear ( ) ;
75+ await startTimeBox . sendKeys ( startTime ) ;
76+
77+ const endTimeBox = await driver . findElement ( By . id ( "submittingTime1SubmissionNotice" + index ) ) ;
78+ expect ( ( await endTimeBox . getAttribute ( "value" ) ) ) . toBe ( expectedEndTimeBox ) ;
79+ await endTimeBox . clear ( ) ;
80+ await endTimeBox . sendKeys ( endTime ) ;
81+
82+ editButton = await driver . findElement ( By . id ( "sponsorTimeEditButtonSubmissionNotice" + index ) ) ;
83+ await editButton . click ( ) ;
84+
85+ sponsorTimeDisplays = await driver . findElements ( By . className ( "sponsorTimeDisplay" ) ) ;
86+ sponsorTimeDisplay = sponsorTimeDisplays [ index ] ;
87+ await driver . wait ( until . elementTextIs ( sponsorTimeDisplay , expectedDisplayedTime ) ) ;
88+ }
0 commit comments