edouard@3436: """ This test opens, builds and runs a new project.
edouard@3424: Test succeeds if runtime's stdout behaves as expected
edouard@3424: """
edouard@3424: 
edouard@3424: import os
edouard@3424: import time
edouard@3424: 
edouard@3424: # allow module import from current test directory's parent
edouard@3424: addImportPath(os.path.dirname(getBundlePath()))
edouard@3424: 
edouard@3424: # common test definitions module
edouard@3424: from sikuliberemiz import *
edouard@3424: 
edouard@3447: def test(app):
edouard@3447:     
edouard@3447:     new_project_path = os.path.join(os.path.abspath(os.path.curdir), "new_test_project")
edouard@3447:     
edouard@3447:     # New project path must exist (usually created in directory selection dialog)
edouard@3447:     os.mkdir(new_project_path)
edouard@3447:     
edouard@3447:     app.WaitIdleUI()
edouard@3447:     
edouard@3447:     # Create new project (opens new project directory selection dialog)
edouard@3447:     app.k.New()
edouard@3447:     
edouard@3447:     app.WaitIdleUI()
edouard@3447:     
edouard@3447:     # Move to "Home" section of file selecor, otherwise address is 
edouard@3447:     # "file ignored" at first run
edouard@3447:     app.type("f", Key.CTRL)
edouard@3698:     app.WaitIdleUI()
edouard@3447:     app.type(Key.ESC)
edouard@3698:     app.WaitIdleUI()
edouard@3447:     app.type(Key.TAB)
edouard@3698:     app.WaitIdleUI()
edouard@3447:     
edouard@3447:     # Enter directory by name
edouard@3447:     app.k.Address()
edouard@3698:     app.WaitIdleUI()
edouard@3447:     
edouard@3447:     # Fill address bar
edouard@3447:     app.type(new_project_path + Key.ENTER)
edouard@3447:     
edouard@3447:     app.WaitIdleUI()
edouard@3447:     
edouard@3447:     # When prompted for creating first program select type ST
edouard@3447:     app.type(Key.TAB*4)  # go to lang dropdown
edouard@3447:     app.type(Key.DOWN*2) # change selected language
edouard@3447:     app.type(Key.ENTER)  # validate
edouard@3447:     
edouard@3447:     app.WaitIdleUI()
edouard@3447:     
edouard@3447:     # Name created program
edouard@3447:     app.type("Test program")
edouard@3447:     
edouard@3447:     app.WaitIdleUI()
edouard@3447:     
edouard@3447:     # Focus on Variable grid
edouard@3447:     app.type(Key.TAB*4)
edouard@3447:     
edouard@3447:     # Add 2 variables
edouard@3447:     app.type(Key.ADD*2)
edouard@3447:     
edouard@3447:     # Focus on ST text
edouard@3447:     app.WaitIdleUI()
edouard@3447:     
edouard@3447:     app.type(Key.TAB*8)
edouard@3447:     
edouard@3447:     app.type("""\
edouard@3447:     LocalVar0 := LocalVar1;
edouard@3447:     {printf("Test OK\\n");fflush(stdout);}
edouard@3447:     """)
edouard@3447:     
edouard@3447:     app.k.Save()
edouard@3447:     
edouard@3447:     # Close ST POU
edouard@3447:     app.type("w", Key.CTRL)
edouard@3447:     
edouard@3447:     app.WaitIdleUI()
edouard@3447:     
edouard@3447:     # Focus project tree and select root item
edouard@3447:     app.type(Key.TAB)
edouard@3447:     
edouard@3447:     app.type(Key.LEFT)
edouard@3447:     
edouard@3447:     app.type(Key.UP)
edouard@3447:     
edouard@3447:     # Edit root item
edouard@3447:     app.type(Key.ENTER)
edouard@3447:     
edouard@3447:     app.WaitIdleUI()
edouard@3447:     
edouard@3447:     # Switch to config tab
edouard@3447:     app.type(Key.RIGHT*2)
edouard@3447:     
edouard@3447:     # Focus on URI
edouard@3447:     app.type(Key.TAB)
edouard@3447:     
edouard@3447:     # Set URI
edouard@3447:     app.type("LOCAL://")
edouard@3447:     
edouard@3447:     # FIXME: Select other field to ensure URI is validated
edouard@3447:     app.type(Key.TAB)
edouard@3447:     
edouard@3447:     app.k.Save()
edouard@3447:     
edouard@3447:     # Close project config editor
edouard@3447:     app.type("w", Key.CTRL)
edouard@3447:     
edouard@3447:     app.WaitIdleUI()
edouard@3447:     
edouard@3447:     # Focus seems undefined at that time (FIXME)
edouard@3447:     # Force focussing on "something" so that next shortcut is taken
edouard@3447:     app.type(Key.TAB)
edouard@3447:     
edouard@3447:     app.waitIdleStdout()
edouard@3447:     
edouard@3447:     app.k.Build()
edouard@3447:     
edouard@3720:     app.waitPatternInStdout("Successfully built.", 10)
edouard@3447:     
edouard@3447:     app.k.Connect()
edouard@3447:     
edouard@3447:     app.waitIdleStdout()
edouard@3447:     
edouard@3447:     app.k.Transfer()
edouard@3447:     
edouard@3447:     app.waitIdleStdout()
edouard@3447:     
edouard@3447:     app.k.Run()
edouard@3447:     
edouard@3447:     # wait 10 seconds
edouard@3447:     return app.waitPatternInStdout("Test OK", 10)
edouard@3432: 
edouard@3432: 
edouard@3447: run_test(test)