11package test
22
33import (
4+ "fmt"
45 "net/http"
6+ "os"
7+ "path/filepath"
58 "strconv"
69 "time"
710 "unicode/utf8"
@@ -22,6 +25,8 @@ var perTestTimeout = 2000 * time.Millisecond
2225var rootDir = browsh .Shell ("git rev-parse --show-toplevel" )
2326var testSiteURL = "http://localhost:" + staticFileServerPort
2427var ti * terminfo.Terminfo
28+ var dir , _ = os .Getwd ()
29+ var framesLogFile = fmt .Sprintf (filepath .Join (dir , "frames.log" ))
2530
2631func initTerm () {
2732 // The tests check for true colour RGB values. The only downside to forcing true colour
@@ -48,11 +53,25 @@ func GetFrame() string {
4853 line = 0
4954 }
5055 }
56+ writeFrameLog ("================================================" )
57+ writeFrameLog (ginkgo .CurrentGinkgoTestDescription ().FullTestText )
58+ writeFrameLog ("================================================\n " )
5159 log = "\n " + log + styleDefault
52- ginkgo . GinkgoWriter . Write ([] byte ( log ) )
60+ writeFrameLog ( log )
5361 return frame
5462}
5563
64+ func writeFrameLog (log string ) {
65+ f , err := os .OpenFile (framesLogFile , os .O_WRONLY | os .O_CREATE | os .O_APPEND , 0600 )
66+ if err != nil {
67+ panic (err )
68+ }
69+ defer f .Close ()
70+ if _ , err = f .WriteString (log ); err != nil {
71+ panic (err )
72+ }
73+ }
74+
5675// Trigger the key definition specified by name
5776func triggerUserKeyFor (name string ) {
5877 key := viper .GetStringSlice (name )
@@ -110,7 +129,7 @@ func WaitForPageLoad() {
110129
111130func sleepUntilPageLoad (maxTime time.Duration ) {
112131 start := time .Now ()
113- time .Sleep (50 * time .Millisecond )
132+ time .Sleep (1000 * time .Millisecond )
114133 for time .Since (start ) < maxTime {
115134 if browsh .CurrentTab != nil {
116135 if browsh .CurrentTab .PageState == "parsing_complete" {
@@ -132,6 +151,12 @@ func GotoURL(url string) {
132151 // TODO: Looking for the URL isn't optimal because it could be the same URL
133152 // as the previous test.
134153 gomega .Expect (url ).To (BeInFrameAt (0 , 1 ))
154+ // TODO: hack to work around bug where text sometimes doesn't render on page load.
155+ // Clicking with the mouse triggers a reparse by the web extension
156+ mouseClick (3 , 6 )
157+ time .Sleep (100 * time .Millisecond )
158+ mouseClick (3 , 6 )
159+ time .Sleep (500 * time .Millisecond )
135160}
136161
137162func mouseClick (x , y int ) {
@@ -199,31 +224,49 @@ func startStaticFileServer() {
199224 http .ListenAndServe (":" + staticFileServerPort , serverMux )
200225}
201226
202- func startBrowsh () {
227+ func initBrowsh () {
203228 browsh .IsTesting = true
204229 simScreen = tcell .NewSimulationScreen ("UTF-8" )
205230 browsh .Initialise ()
206- browsh .TTYStart (simScreen )
231+
232+ }
233+
234+ func stopFirefox () {
235+ browsh .Log ("Attempting to kill all firefox processes" )
236+ browsh .IsConnectedToWebExtension = false
237+ browsh .Shell (rootDir + "/webext/contrib/firefoxheadless.sh kill" )
238+ time .Sleep (500 * time .Millisecond )
207239}
208240
209241func runeCount (text string ) int {
210242 return utf8 .RuneCountInString (text )
211243}
212244
213245var _ = ginkgo .BeforeEach (func () {
246+ browsh .Log ("Attempting to restart WER Firefox..." )
247+ stopFirefox ()
248+ browsh .ResetTabs ()
249+ browsh .StartFirefox ()
250+ sleepUntilPageLoad (startupWait )
214251 browsh .IsMonochromeMode = false
215252 browsh .Log ("\n ---------" )
216253 browsh .Log (ginkgo .CurrentGinkgoTestDescription ().FullTestText )
217254 browsh .Log ("---------" )
218255})
219256
220257var _ = ginkgo .BeforeSuite (func () {
258+ os .Truncate (framesLogFile , 0 )
221259 initTerm ()
260+ initBrowsh ()
261+ stopFirefox ()
222262 go startStaticFileServer ()
223- go startBrowsh ()
224- sleepUntilPageLoad (startupWait )
263+ go browsh .TTYStart (simScreen )
264+ // Firefox seems to take longer to die after its first run
265+ time .Sleep (500 * time .Millisecond )
266+ stopFirefox ()
267+ time .Sleep (5000 * time .Millisecond )
225268})
226269
227270var _ = ginkgo .AfterSuite (func () {
228- browsh . Shell ( rootDir + "/webext/contrib/firefoxheadless.sh kill" )
271+ stopFirefox ( )
229272})
0 commit comments