github.com/saucelabs/saucectl@v0.175.1/internal/cmd/ini/xcuitest.go (about) 1 package ini 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/rs/zerolog/log" 8 cmds "github.com/saucelabs/saucectl/internal/cmd" 9 "github.com/saucelabs/saucectl/internal/config" 10 "github.com/saucelabs/saucectl/internal/segment" 11 "github.com/saucelabs/saucectl/internal/usage" 12 "github.com/saucelabs/saucectl/internal/xcuitest" 13 "github.com/spf13/cobra" 14 "golang.org/x/text/cases" 15 "golang.org/x/text/language" 16 ) 17 18 func XCUITestCmd() *cobra.Command { 19 cfg := &initConfig{ 20 frameworkName: xcuitest.Kind, 21 } 22 23 cmd := &cobra.Command{ 24 Use: "xcuitest", 25 Short: "Bootstrap an XCUITest project.", 26 SilenceUsage: true, 27 Run: func(cmd *cobra.Command, args []string) { 28 tracker := segment.DefaultTracker 29 30 go func() { 31 tracker.Collect( 32 cases.Title(language.English).String(cmds.FullName(cmd)), 33 usage.Properties{}.SetFlags(cmd.Flags()), 34 ) 35 _ = tracker.Close() 36 }() 37 38 err := Run(cmd, cfg) 39 if err != nil { 40 log.Err(err).Msg("failed to execute init command") 41 os.Exit(1) 42 } 43 }, 44 } 45 46 cmd.Flags().StringVar(&cfg.app, "app", "", "Path to application under test.") 47 cmd.Flags().StringVar(&cfg.testApp, "test-app", "", "Path to test application.") 48 cmd.Flags().StringSliceVar(&cfg.otherApps, "other-apps", []string{}, "Path to additional applications.") 49 cmd.Flags().StringVar(&cfg.artifactWhenStr, "artifacts-when", "fail", "When to download artifacts.") 50 cmd.Flags().Var(&cfg.simulatorFlag, "simulator", "The iOS simulator to use for testing.") 51 cmd.Flags().Var(&cfg.deviceFlag, "device", "The device to use for testing.") 52 53 return cmd 54 } 55 56 func configureXCUITest(cfg *initConfig) interface{} { 57 suites := []xcuitest.Suite{} 58 if cfg.device.Name != "" { 59 suites = append(suites, xcuitest.Suite{ 60 Name: fmt.Sprintf("xcuitest - %s", cfg.device.Name), 61 Devices: []config.Device{cfg.device}, 62 App: cfg.app, 63 TestApp: cfg.testApp, 64 OtherApps: cfg.otherApps, 65 }) 66 } 67 if cfg.simulator.Name != "" { 68 suites = append(suites, xcuitest.Suite{ 69 Name: fmt.Sprintf("xcuitest - %s", cfg.simulator.Name), 70 Simulators: []config.Simulator{cfg.simulator}, 71 App: cfg.app, 72 TestApp: cfg.testApp, 73 OtherApps: cfg.otherApps, 74 }) 75 } 76 return xcuitest.Project{ 77 TypeDef: config.TypeDef{ 78 APIVersion: xcuitest.APIVersion, 79 Kind: xcuitest.Kind, 80 }, 81 Sauce: config.SauceConfig{ 82 Region: cfg.region, 83 Concurrency: cfg.concurrency, 84 }, 85 Xcuitest: xcuitest.Xcuitest{ 86 OtherApps: cfg.otherApps, 87 }, 88 Suites: suites, 89 Artifacts: config.Artifacts{ 90 Download: config.ArtifactDownload{ 91 When: cfg.artifactWhen, 92 Directory: "./artifacts", 93 Match: []string{"*"}, 94 }, 95 }, 96 } 97 }