How to use Context method of launcher Package

Best Rod code snippet using launcher.Context

app_drag_and_drop.go

Source:app_drag_and_drop.go Github

copy

Full Screen

...42 }},43 })44}45// AppDragAndDrop tests the functionality of dragging and dropping on app icons.46func AppDragAndDrop(ctx context.Context, s *testing.State) {47 cr := s.FixtValue().(*chrome.Chrome)48 tconn, err := cr.TestAPIConn(ctx)49 if err != nil {50 s.Fatal("Failed to create test API connection: ", err)51 }52 ui := uiauto.New(tconn)53 cleanupCtx := ctx54 ctx, cancel := ctxutil.Shorten(ctx, 10*time.Second)55 defer cancel()56 for _, subtest := range []struct {57 modeName string58 isTablet bool59 }{60 {"drag and drop app in clamshell mode", false},61 {"drag and drop app in tablet mode", true},62 } {63 cleanup, err := ash.EnsureTabletModeEnabled(ctx, tconn, subtest.isTablet)64 if err != nil {65 s.Fatal("Failed to set tablet mode to be tabletMode: ", err)66 }67 defer cleanup(cleanupCtx)68 productivityLauncher := s.Param().(bool)69 f := func(ctx context.Context, s *testing.State) {70 defer faillog.DumpUITreeWithScreenshotOnError(cleanupCtx, s.OutDir(), s.HasError, cr, subtest.modeName+"_ui_dump")71 if !subtest.isTablet {72 if err := ash.WaitForLauncherState(ctx, tconn, ash.Closed); err != nil {73 s.Fatal("Launcher not closed after transition to clamshell mode: ", err)74 }75 }76 usingBubbleLauncher := productivityLauncher && !subtest.isTablet77 // Open the Launcher and go to Apps list page.78 if usingBubbleLauncher {79 if err := launcher.OpenBubbleLauncher(tconn)(ctx); err != nil {80 s.Fatal("Failed to open bubble launcher: ", err)81 }82 } else {83 if err := launcher.Open(tconn)(ctx); err != nil {84 s.Fatal("Failed to open the launcher: ", err)85 }86 }87 if err := launcher.WaitForStableNumberOfApps(ctx, tconn); err != nil {88 s.Fatal("Failed to wait for item count in app list to stabilize: ", err)89 }90 // Each subtest requires at least 3 items on the current page - the first page may have a (default) page break after several91 // default apps, and depending on the device may not have enough apps to satisfy this requirement.92 // To work around this, start the test on the second launcher page.93 // startPage defines which page starts testing.94 startPage := 295 if !usingBubbleLauncher {96 if err := switchToPage(ui, startPage)(ctx); err != nil {97 s.Fatal("Failed to switch to second page for test: ", err)98 }99 }100 firstItem, err := launcher.FirstNonRecentAppItem(ctx, tconn)101 if err != nil {102 s.Fatal("Failed to count recent apps items: ", err)103 }104 if !usingBubbleLauncher {105 firstItem, err = getFirstItemOnCurrentPage(ctx, tconn, firstItem)106 if err != nil {107 s.Fatal("Failed to get the first item on the current page: ", err)108 }109 }110 if err := dragIconToIcon(ctx, tconn, ui, firstItem, productivityLauncher); err != nil {111 s.Fatal("Failed to drag the first icon to the second icon: ", err)112 }113 if !usingBubbleLauncher {114 if err := dragIconToNextPage(ctx, tconn, ui, firstItem, startPage); err != nil {115 s.Fatal("Failed to drag the first icon to next page: ", err)116 }117 } else {118 dropIndex, err := dragFirstIconToScrollableContainerBottom(ctx, tconn, ui)119 if err != nil {120 s.Fatal("Failed to drag the first icon to bottom of scrollable container: ", err)121 }122 if err := dragIconToScrollableContainerTop(ctx, tconn, ui, dropIndex); err != nil {123 s.Fatal("Failed to drag the last item to top of scrollable container: ", err)124 }125 }126 }127 if !s.Run(ctx, subtest.modeName, f) {128 s.Errorf("Failed to run subtest %q", subtest.modeName)129 }130 }131}132// dragIconToIcon drags an app list item at firstItem index in the current app list page to an item at index firstItem + 2, creating a folder.133// It then removes all items from the folder, and verifies the original item gets dropped into a different location.134// productivityLauncher indicates whether the test is run for productivityLauncher, which subtly changes folder interfactions.135func dragIconToIcon(ctx context.Context, tconn *chrome.TestConn, ui *uiauto.Context, firstItem int, productivityLauncher bool) error {136 srcInfo, err := ui.Info(ctx, nodewith.HasClass(launcher.ExpandedItemsClass).Nth(firstItem))137 if err != nil {138 return errors.Wrap(err, "failed to get information of first icon")139 }140 src := launcher.AppItemViewFinder(srcInfo.Name)141 locBefore, err := ui.Location(ctx, src)142 if err != nil {143 return errors.Wrap(err, "failed to get location of icon before dragging")144 }145 // Because launcher.DragIconToIcon can't drag the icon to the middle of two adjacent icons,146 // and the srcIcon and destIcon will be merged into a folder.147 // Use launcher.DragIconToIcon and launcher.RemoveIconFromFolder to change the position of the icon while avoiding merging into a folder.148 if err := launcher.DragIconToIcon(tconn, firstItem, firstItem+2)(ctx); err != nil {149 return errors.Wrap(err, "failed to drag the first icon to the third icon")150 }151 // For productivity launcher, folders get automatically opened after getting created by dragging - make sure the created folder gets closed.152 if productivityLauncher {153 if err := launcher.CloseFolderView(ctx, tconn); err != nil {154 return errors.Wrap(err, "failed to close the folder")155 }156 }157 if err := launcher.RemoveIconFromFolder(tconn, launcher.UnnamedFolderFinder)(ctx); err != nil {158 return errors.Wrap(err, "failed to drag out the icon from folder")159 }160 // Productivity launcher supports single-item folders, so the folder should still exist after removing second to last item.161 if productivityLauncher {162 if err := launcher.RemoveIconFromFolder(tconn, launcher.UnnamedFolderFinder)(ctx); err != nil {163 return errors.Wrap(err, "failed to drag out the icon from single-item folder")164 }165 }166 locAfter, err := ui.Location(ctx, src)167 if err != nil {168 return errors.Wrap(err, "failed to get location of icon after dragging")169 }170 if (locBefore.CenterX() == locAfter.CenterX()) &&171 (locBefore.CenterY() == locAfter.CenterY()) {172 return errors.New("failed to verify dragged icon in the new position")173 }174 return nil175}176// dragIconToNextPage drags the first icon at index itemIndex in the app list UI from the startPage to the next page.177func dragIconToNextPage(ctx context.Context, tconn *chrome.TestConn, ui *uiauto.Context, itemIndex, startPage int) error {178 srcInfo, err := ui.Info(ctx, nodewith.HasClass(launcher.ExpandedItemsClass).Nth(itemIndex))179 if err != nil {180 return errors.Wrap(err, "failed to get information of first icon")181 }182 // Checks item is in current startPage.183 if _, err := isItemInPage(ctx, ui, srcInfo.Name, startPage); err != nil {184 return errors.Wrap(err, "failed to identify page before dragging")185 }186 if err := launcher.DragIconAtIndexToNextPage(tconn, itemIndex)(ctx); err != nil {187 return errors.Wrap(err, "failed to drag icon to next page")188 }189 nextPage := startPage + 1190 if _, err := isItemInPage(ctx, ui, srcInfo.Name, nextPage); err != nil {191 return errors.Wrap(err, "failed to identify page after dragging")192 }193 testing.ContextLogf(ctx, "%q has been moved to page %d", srcInfo.Name, nextPage)194 // Return to the previous page after verifying that dropped app should be in the new page.195 if err := switchToPage(ui, startPage)(ctx); err != nil {196 return errors.Wrap(err, "failed to recovery to the previous page")197 }198 return nil199}200// dragFirstIconToScrollableContainerBottom drags the first item in the scrollable apps grid view to the last available slot in the view.201// Returns the index of the drag item view in the scrollable app grid after successful drag operation.202func dragFirstIconToScrollableContainerBottom(ctx context.Context, tconn *chrome.TestConn, ui *uiauto.Context) (int, error) {203 scrollableGridItems := nodewith.ClassName(launcher.ExpandedItemsClass).Ancestor(nodewith.ClassName("ScrollableAppsGridView"))204 dragItem := scrollableGridItems.Nth(0)205 dragItemInfo, err := ui.Info(ctx, dragItem)206 if err != nil {207 return -1, errors.Wrap(err, "failed to get drag item info")208 }209 dragItemName := dragItemInfo.Name210 allItemsInfo, err := ui.NodesInfo(ctx, scrollableGridItems)211 if err != nil {212 return -1, errors.Wrap(err, "failed to get list of grid items")213 }214 itemCount := len(allItemsInfo)215 targetItem := scrollableGridItems.Nth(itemCount - 1)216 if err := launcher.DragItemInBubbleLauncherWithScrolling(ctx, tconn, ui, dragItem, targetItem, false /*up*/); err != nil {217 return -1, errors.Wrap(err, "bubble launcher scroll failed")218 }219 // Drag item should have been moved right of the first item in the scrollable grid.220 lastItemInfo, err := ui.Info(ctx, scrollableGridItems.Nth(itemCount-1))221 if err != nil {222 return -1, errors.Wrap(err, "failed to get second app item info")223 }224 if dragItemName != lastItemInfo.Name {225 return -1, errors.Wrapf(err, "Last item %s is not the drag item %s", lastItemInfo.Name, dragItemInfo.Name)226 }227 return itemCount - 1, nil228}229// dragIconToScrollableContainerTop drags an app list item at itemIndex in the scrollable apps grid view to the slot after the first item.230func dragIconToScrollableContainerTop(ctx context.Context, tconn *chrome.TestConn, ui *uiauto.Context, itemIndex int) error {231 scrollableGridItems := nodewith.ClassName(launcher.ExpandedItemsClass).Ancestor(nodewith.ClassName("ScrollableAppsGridView"))232 dragItem := scrollableGridItems.Nth(itemIndex)233 dragItemInfo, err := ui.Info(ctx, dragItem)234 if err != nil {235 return errors.Wrap(err, "failed to get drag item info")236 }237 dragItemName := dragItemInfo.Name238 targetItem := scrollableGridItems.Nth(0)239 if err := launcher.DragItemInBubbleLauncherWithScrolling(ctx, tconn, ui, dragItem, targetItem, true /*up*/); err != nil {240 return errors.Wrap(err, "bubble launcher scroll failed")241 }242 // Drag item should have been moved right of the first item in the scrollable grid.243 secondItemInfo, err := ui.Info(ctx, scrollableGridItems.Nth(1))244 if err != nil {245 return errors.Wrap(err, "failed to get second app item info")246 }247 if dragItemName != secondItemInfo.Name {248 return errors.Wrapf(err, "Last item %s is not the drag item %s", secondItemInfo.Name, dragItemName)249 }250 return nil251}252// getFirstItemOnCurrentPage returns the index on the first app list item that's on the current page253func getFirstItemOnCurrentPage(ctx context.Context, tconn *chrome.TestConn, minIndex int) (int, error) {254 for currentIndex := minIndex; ; currentIndex++ {255 itemOnCurrentPage, err := launcher.IsItemOnCurrentPage(ctx, tconn, nodewith.ClassName(launcher.ExpandedItemsClass).Nth(currentIndex))256 if err != nil {257 return -1, errors.Wrap(err, "checking whether item is on page failed")258 }259 if itemOnCurrentPage {260 return currentIndex, nil261 }262 }263}264// switchToPage switches to the target page by clicking the switch button.265func switchToPage(ui *uiauto.Context, targetPage int) action.Action {266 pageNodeName := regexp.MustCompile(fmt.Sprintf(`Page %d of \d+`, targetPage))267 return uiauto.Combine("switch launcher page",268 ui.LeftClick(nodewith.Role(role.Button).NameRegex(pageNodeName)),269 ui.WaitForLocation(nodewith.HasClass(launcher.ExpandedItemsClass).First()), // Wait for item to be stable.270 )271}272// isItemInPage checks if the target item is located in the expected page.273// Note that this method may change the current page while switching to other page.274func isItemInPage(ctx context.Context, ui *uiauto.Context, itemName string, targetPage int) (bool, error) {275 if err := switchToPage(ui, targetPage)(ctx); err != nil {276 return false, errors.Wrap(err, "failed to switch to page")277 }278 onscreen, err := isItemOnscreen(ctx, ui, itemName)279 if err != nil {280 return false, errors.Wrap(err, "failed to find item in certain page")281 }282 return onscreen, nil283}284// isItemOnscreen checks whether the target is on the current page.285func isItemOnscreen(ctx context.Context, ui *uiauto.Context, itemName string) (bool, error) {286 itemView := launcher.AppItemViewFinder(itemName)287 item := nodewith.Name(itemName).HasClass("Label").Ancestor(itemView)288 info, err := ui.Info(ctx, item)289 if err != nil {290 return false, err291 }292 return !info.State[state.Offscreen], nil293}...

Full Screen

Full Screen

hotseat_scroll_perf.go

Source:hotseat_scroll_perf.go Github

copy

Full Screen

...91 default:92 return "unknown"93 }94}95func scrollToEnd(ctx context.Context, tconn *chrome.TestConn, d direction) error {96 var scrollCount int97 for {98 // Calculate the suitable scroll offset to go to a new shelf page.99 info, err := ash.FetchScrollableShelfInfoForState(ctx, tconn, &ash.ShelfState{})100 if err != nil {101 return err102 }103 var pageOffset float32104 if d == scrollToLeft {105 pageOffset = -info.PageOffset106 } else {107 pageOffset = info.PageOffset108 }109 // Calculate the target scroll offset based on pageOffset.110 if info, err = ash.FetchScrollableShelfInfoForState(ctx, tconn, &ash.ShelfState{ScrollDistance: pageOffset}); err != nil {111 return err112 }113 // Choose the arrow button to be clicked based on the scroll direction.114 var arrowBounds coords.Rect115 if d == scrollToLeft {116 arrowBounds = info.LeftArrowBounds117 } else {118 arrowBounds = info.RightArrowBounds119 }120 if arrowBounds.Width == 0 {121 // Have scrolled to the end. Break the loop.122 break123 }124 if err := ash.ScrollShelfAndWaitUntilFinish(ctx, tconn, arrowBounds, info.TargetMainAxisOffset); err != nil {125 return err126 }127 scrollCount = scrollCount + 1128 }129 if scrollCount == 0 {130 return errors.New("Scroll animation should be triggered at least one time in the loop")131 }132 return nil133}134func runShelfScroll(ctx context.Context, tconn *chrome.TestConn) error {135 if err := scrollToEnd(ctx, tconn, scrollToRight); err != nil {136 return err137 }138 if err := scrollToEnd(ctx, tconn, scrollToLeft); err != nil {139 return err140 }141 return nil142}143func shelfAnimationHistogramName(mode uiMode, state uiState) string {144 const baseHistogramName = "Apps.ScrollableShelf.AnimationSmoothness"145 comps := []string{baseHistogramName, mode.String(), state.String()}146 return strings.Join(comps, ".")147}148func prepareFetchShelfScrollSmoothness(ctx context.Context, tconn *chrome.TestConn, mode uiMode, state uiState) (func(ctx context.Context) error, error) {149 cleanupFuncs := make([]func(ctx context.Context) error, 0, 3)150 cleanupAll := func(ctx context.Context) error {151 var firstErr error152 var errorNum int153 for _, f := range cleanupFuncs {154 if err := f(ctx); err != nil {155 errorNum++156 if firstErr == nil {157 firstErr = err158 }159 }160 }161 if errorNum > 0 {162 return errors.Wrapf(firstErr, "there are %d errors; first error", errorNum)163 }164 return nil165 }166 isInTabletMode := mode == inTabletMode167 isLauncherVisible := state == launcherIsVisible168 launcherTargetState := ash.Closed169 if isLauncherVisible {170 launcherTargetState = ash.FullscreenAllApps171 }172 if state == overviewIsVisible {173 // Hide notifications before testing overview, so notifications are not shown over the hotseat in tablet mode.174 if err := ash.CloseNotifications(ctx, tconn); err != nil {175 return cleanupAll, errors.Wrap(err, "failed to close all notifications")176 }177 // Enter overview mode.178 if err := ash.SetOverviewModeAndWait(ctx, tconn, true); err != nil {179 return cleanupAll, errors.Wrap(err, "failed to enter into the overview mode")180 }181 // Close overview mode after animation smoothness data is collected for it.182 cleanupFuncs = append(cleanupFuncs, func(ctx context.Context) error {183 return ash.SetOverviewModeAndWait(ctx, tconn, false)184 })185 } else if isInTabletMode && !isLauncherVisible {186 // Hide launcher by launching the file app.187 files, err := filesapp.Launch(ctx, tconn)188 if err != nil {189 return cleanupAll, errors.Wrap(err, "failed to hide the home launcher by activating an app")190 }191 // App should be open until the animation smoothness data is collected for in-app shelf.192 cleanupFuncs = append(cleanupFuncs, files.Close)193 tsw, tcc, err := touch.NewTouchscreenAndConverter(ctx, tconn)194 if err != nil {195 return cleanupAll, errors.Wrap(err, "failed to create the touch controller")196 }197 cleanupFuncs = append(cleanupFuncs, func(context.Context) error {198 return tsw.Close()199 })200 stw, err := tsw.NewSingleTouchWriter()201 if err != nil {202 return cleanupAll, errors.Wrap(err, "failed to get the single touch writer")203 }204 // Swipe up the hotseat.205 if err := ash.SwipeUpHotseatAndWaitForCompletion(ctx, tconn, stw, tcc); err != nil {206 return cleanupAll, errors.Wrap(err, "failed to test the in-app shelf")207 }208 } else if !isInTabletMode && isLauncherVisible {209 // Show launcher fullscreen.210 if err := ash.TriggerLauncherStateChange(ctx, tconn, ash.AccelShiftSearch); err != nil {211 return cleanupAll, errors.Wrap(err, "failed to switch to fullscreen")212 }213 cleanupFuncs = append(cleanupFuncs, func(ctx context.Context) error {214 return ash.TriggerLauncherStateChange(ctx, tconn, ash.AccelSearch)215 })216 // Verify the launcher's state.217 if err := ash.WaitForLauncherState(ctx, tconn, launcherTargetState); err != nil {218 return cleanupAll, errors.Wrapf(err, "failed to switch the state to %s", launcherTargetState)219 }220 }221 // Hotseat in different states may have different bounds. So enter shelf overflow mode after tablet/clamshell switch and gesture swipe.222 if err := ash.EnterShelfOverflow(ctx, tconn); err != nil {223 return cleanupAll, err224 }225 if err := ash.WaitForStableShelfBounds(ctx, tconn); err != nil {226 return cleanupAll, errors.Wrap(err, "failed to wait for stable shelf bounds")227 }228 return cleanupAll, nil229}230// HotseatScrollPerf records the animation smoothness for shelf scroll animation.231func HotseatScrollPerf(ctx context.Context, s *testing.State) {232 // Ensure display on to record ui performance correctly.233 if err := power.TurnOnDisplay(ctx); err != nil {234 s.Fatal("Failed to turn on display: ", err)235 }236 cr := s.FixtValue().(*chrome.Chrome)237 tconn, err := cr.TestAPIConn(ctx)238 if err != nil {239 s.Fatal("Failed to create Test API connection: ", err)240 }241 defer faillog.DumpUITreeOnError(ctx, s.OutDir(), s.HasError, tconn)242 runner := perfutil.NewRunner(cr.Browser())243 var mode uiMode244 if s.Param().(bool) {245 mode = inTabletMode246 } else {247 mode = inClamshellMode248 }249 cleanup, err := ash.EnsureTabletModeEnabled(ctx, tconn, s.Param().(bool))250 if err != nil {251 s.Fatalf("Failed to ensure the tablet-mode enabled status to %v: %v", s.Param().(bool), err)252 }253 defer cleanup(ctx)254 type testSetting struct {255 state uiState256 mode uiMode257 }258 settings := []testSetting{259 {260 state: launcherIsHidden,261 mode: mode,262 },263 {264 state: overviewIsVisible,265 mode: mode,266 },267 {268 state: launcherIsVisible,269 mode: mode,270 },271 }272 for _, setting := range settings {273 cleanupFunc, err := prepareFetchShelfScrollSmoothness(ctx, tconn, setting.mode, setting.state)274 if err != nil {275 if err := cleanupFunc(ctx); err != nil {276 s.Error("Failed to cleanup the preparation: ", err)277 }278 s.Fatalf("Failed to prepare for %v: %v", setting.state, err)279 }280 var suffix string281 if setting.state == overviewIsVisible {282 suffix = "OverviewShown"283 }284 passed := runner.RunMultiple(ctx, s, setting.state.String(), perfutil.RunAndWaitAll(tconn, func(ctx context.Context) error {285 return runShelfScroll(ctx, tconn)286 }, shelfAnimationHistogramName(setting.mode, setting.state)),287 perfutil.StoreAll(perf.BiggerIsBetter, "percent", suffix))288 if err := cleanupFunc(ctx); err != nil {289 s.Fatalf("Failed to cleanup for %v: %v", setting.state, err)290 }291 if !passed {292 return293 }294 }295 if err := runner.Values().Save(ctx, s.OutDir()); err != nil {296 s.Fatal("Failed to save performance data in file: ", err)297 }298}...

Full Screen

Full Screen

search_installed_apps.go

Source:search_installed_apps.go Github

copy

Full Screen

...52 }},53 })54}55// SearchInstalledApps tests that apps installed from CWS appear in launcher.56func SearchInstalledApps(ctx context.Context, s *testing.State) {57 cleanupCtx := ctx58 ctx, cancel := ctxutil.Shorten(ctx, 10*time.Second)59 defer cancel()60 cr := s.FixtValue().(*chrome.Chrome)61 tconn, err := cr.TestAPIConn(ctx)62 if err != nil {63 s.Fatal("Failed to create Test API connection: ", err)64 }65 ui := uiauto.New(tconn)66 kw, err := input.Keyboard(ctx)67 if err != nil {68 s.Fatal("Failed to get keyboard: ", err)69 }70 defer kw.Close()71 testCase := s.Param().(launcher.TestCase)72 tabletMode := testCase.TabletMode73 if !tabletMode {74 defer func(ctx context.Context) {75 if err := ui.RetryUntil(76 kw.AccelAction("esc"),77 func(ctx context.Context) error { return ash.WaitForLauncherState(ctx, tconn, ash.Closed) },78 )(ctx); err != nil {79 testing.ContextLog(ctx, "Failed to dismiss launcher: ", err)80 }81 }(cleanupCtx)82 }83 cleanup, err := ash.EnsureTabletModeEnabled(ctx, tconn, tabletMode)84 if err != nil {85 s.Fatal("Failed to ensure clamshell/tablet mode: ", err)86 }87 defer cleanup(cleanupCtx)88 // When a DUT switches from tablet mode to clamshell mode, sometimes it takes a while to settle down.89 if !tabletMode {90 if err := ash.WaitForLauncherState(ctx, tconn, ash.Closed); err != nil {91 s.Fatal("Launcher not closed after transition to clamshell mode: ", err)92 }93 }94 cwsapp := newCwsAppGoogleDrawings(cr, tconn)95 if err := cwsapp.install(ctx); err != nil {96 s.Fatal("Failed to install an app from Chrome Web Store: ", err)97 }98 defer cwsapp.uninstall(cleanupCtx)99 if err := uiauto.Combine("open Launcher and verify the app appears in search result",100 launcher.Open(tconn),101 launcher.Search(tconn, kw, cwsapp.name),102 func(ctx context.Context) error {103 return ui.WaitUntilExists(launcher.CreateAppSearchFinder(ctx, tconn, cwsapp.name))(ctx)104 },105 )(ctx); err != nil {106 s.Fatal("Failed to verify that the app is in Launcher: ", err)107 }108 defer func(ctx context.Context) {109 faillog.SaveScreenshotOnError(ctx, cr, s.OutDir(), s.HasError)110 faillog.DumpUITreeOnError(ctx, s.OutDir(), s.HasError, tconn)111 }(cleanupCtx)112}113// cwsAppGoogleDrawings defines the cws-app `Google Drawings`.114type cwsAppGoogleDrawings struct {115 cr *chrome.Chrome116 tconn *chrome.TestConn117 id string118 name string119 cwsURL string120 app *cws.App121}122// newCwsAppGoogleDrawings returns the instance of cwsAppGoogleDrawings.123func newCwsAppGoogleDrawings(cr *chrome.Chrome, tconn *chrome.TestConn) *cwsAppGoogleDrawings {124 const (125 id = "mkaakpdehdafacodkgkpghoibnmamcme"126 name = "Google Drawings"127 url = "https://chrome.google.com/webstore/detail/google-drawings/mkaakpdehdafacodkgkpghoibnmamcme"128 )129 return &cwsAppGoogleDrawings{130 cr: cr,131 tconn: tconn,132 id: id,133 name: name,134 cwsURL: url,135 app: &cws.App{Name: name, URL: url},136 }137}138// install installs the cws-app via Chrome web store.139func (c *cwsAppGoogleDrawings) install(ctx context.Context) error {140 isInstalled, err := ash.ChromeAppInstalled(ctx, c.tconn, c.id)141 if err != nil {142 return errors.Wrap(err, "failed to check CWS app's existance")143 }144 if isInstalled {145 return nil146 }147 testing.ContextLogf(ctx, "Install CWS app: %q", c.name)148 return cws.InstallApp(ctx, c.cr, c.tconn, *c.app)149}150// uninstall uninstalls the cws-app via ossettings.151func (c *cwsAppGoogleDrawings) uninstall(ctx context.Context) error {152 isInstalled, err := ash.ChromeAppInstalled(ctx, c.tconn, c.id)153 if err != nil {154 return errors.Wrap(err, "failed to check CWS app's existance")155 }156 if !isInstalled {157 return nil158 }159 defer func() {160 settings := ossettings.New(c.tconn)161 settings.Close(ctx)162 }()163 testing.ContextLogf(ctx, "Uninstall CWS app: %q", c.name)164 return ossettings.UninstallApp(ctx, c.tconn, c.cr, c.name, c.id)165}...

Full Screen

Full Screen

Context

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)4 defer cancel()5 ctx = context.WithValue(ctx, "name", "Naveen")6 ctx = context.WithValue(ctx, "id", 123)7 ctx = context.WithValue(ctx, "duration", 3*time.Second)8 if err := launcher(ctx); err != nil {9 log.Fatal(err)10 }11}12import (13func launcher(ctx context.Context) error {14 name := ctx.Value("name").(string)15 id := ctx.Value("id").(int)16 duration := ctx.Value("duration").(time.Duration)17 fmt.Println("Name is", name)18 fmt.Println("ID is", id)19 fmt.Println("Duration is", duration)20}21import (22func main() {23 ctx, cancel := context.WithCancel(context.Background())24 defer cancel()25 ctx = context.WithValue(ctx, "name", "Naveen")26 ctx = context.WithValue(ctx, "id", 123)27 ctx = context.WithValue(ctx, "duration", 3*time.Second)28 if err := launcher(ctx); err != nil {29 fmt.Println(err)30 }31}32func launcher(ctx context.Context) error {33 name := ctx.Value("name").(string)34 id := ctx.Value("id").(int)35 duration := ctx.Value("duration").(time.Duration)36 fmt.Println("Name is", name)37 fmt.Println("ID is", id)38 fmt.Println("Duration is", duration)39}

Full Screen

Full Screen

Context

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx, cancel := context.WithCancel(context.Background())4 defer cancel()5 go func() {6 cancel()7 }()8 fmt.Println("About to sleep for 10 seconds")9 select {10 case <-time.After(10 * time.Second):11 case <-ctx.Done():12 fmt.Println("Context done")13 }14}15import (16func main() {17 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)18 defer cancel()19 go func() {20 cancel()21 }()22 fmt.Println("About to sleep for 10 seconds")23 select {24 case <-time.After(10 * time.Second):25 case <-ctx.Done():26 fmt.Println("Context done")27 }28}29import (30func main() {31 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)32 defer cancel()33 go func() {34 cancel()35 }()36 fmt.Println("About to sleep for 10 seconds")37 select {38 case <-time.After(10 * time.Second):39 case <-ctx.Done():40 fmt.Println("Context done")41 }42}43import (44func main() {45 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)46 defer cancel()47 go func() {48 cancel()49 }()50 fmt.Println("About to sleep for 10 seconds")51 select {52 case <-time.After(10 * time.Second):53 case <-ctx.Done():54 fmt.Println("Context done")55 }56}

Full Screen

Full Screen

Context

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := cron.New()4 c.AddFunc("*/5 * * * * *", func() {5 fmt.Println("Every 5 seconds")6 })7 c.AddFunc("*/2 * * * * *", func() {8 fmt.Println("Every 2 seconds")9 })10 c.Start()11 defer c.Stop()12 time.Sleep(10 * time.Second)13}14import (15func main() {16 ctx, cancel := context.WithCancel(context.Background())17 c := cron.New()18 c.AddFunc("*/5 * * * * *", func() {19 fmt.Println("Every 5 seconds")20 })21 c.AddFunc("*/2 * * * * *", func() {22 fmt.Println("Every 2 seconds")23 })24 c.Start()25 defer c.Stop()26 time.Sleep(10 * time.Second)27 cancel()28}29import (30func main() {31 ctx, cancel := context.WithCancel(context.Background())32 c := cron.New()33 c.AddFunc("*/5 * * * * *", func() {34 fmt.Println("Every 5 seconds")35 })36 c.AddFunc("*/2 * * * * *", func() {37 fmt.Println("Every 2 seconds")38 })39 c.Start()40 defer c.Stop()41 time.Sleep(10 * time.Second)42 cancel()43}44import (45func main() {46 ctx, cancel := context.WithCancel(context.Background())47 c := cron.New()48 c.AddFunc("*/5 * * * * *", func() {49 fmt.Println("Every 5 seconds")50 })51 c.AddFunc("*/2 * * * * *", func() {52 fmt.Println("Every 2 seconds")53 })54 c.Start()55 defer c.Stop()56 time.Sleep(10 * time.Second)

Full Screen

Full Screen

Context

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := cron.New()4 c.AddFunc("0 0 1 * * *", func() { fmt.Println("Every day at 1:00am") })5 c.AddFunc("@hourly", func() { fmt.Println("Every hour") })6 c.AddFunc("@every 1h30m", func() { fmt.Println("Every hour thirty") })7 c.Start()8 select {}9}10import (11func main() {12 c := cron.New()13 c.AddFunc("0 0 1 * * *", func() { fmt.Println("Every day at 1:00am") })14 c.AddFunc("@hourly", func() { fmt.Println("Every hour") })15 c.AddFunc("@every 1h30m", func() { fmt.Println("Every hour thirty") })16 c.Start()17 select {}18}19import (20func main() {21 c := cron.New()22 c.AddFunc("0 0 1 * * *", func() { fmt.Println("Every day at 1:00am") })23 c.AddFunc("@hourly", func() { fmt.Println("Every hour") })24 c.AddFunc("@every 1h30m", func() { fmt.Println("Every hour thirty") })25 c.Start()26 select {}27}28import (29func main() {30 c := cron.New()31 c.AddFunc("0 0 1 * * *", func() { fmt.Println("Every day at 1:00am") })32 c.AddFunc("@hourly", func() { fmt.Println("Every hour") })33 c.AddFunc("@every 1h30m", func() { fmt.Println("Every hour thirty") })34 c.Start()35 select {}36}37import (38func main() {

Full Screen

Full Screen

Context

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx, cancel := context.WithCancel(context.Background())4 defer cancel()5 ctx = context.WithValue(ctx, "name", "naveen")6 launch(ctx)7}8func launch(ctx context.Context) {9 fmt.Println("launching rocket")10 name := ctx.Value("name").(string)11 fmt.Println("hello", name)12}13import (14func main() {15 launch()16}17func launch() {18 ctx, cancel := context.WithCancel(context.Background())19 defer cancel()20 ctx = context.WithValue(ctx, "name", "naveen")21 launchRocket(ctx)22}23func launchRocket(ctx context.Context) {24 fmt.Println("launching rocket")25 name := ctx.Value("name").(string)26 fmt.Println("hello", name)27}

Full Screen

Full Screen

Context

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx := newContext()4 cmd := newCommand(ctx)5 err := cmd.Run()6 if err != nil {7 fmt.Println(err)8 os.Exit(1)9 }10}11func newContext() *exec.Cmd {12 ctx := exec.Command("java", "Launcher")13}14func newCommand(ctx *exec.Cmd) *exec.Cmd {15 cmd := exec.Command("java", "Launcher")16}17import java.io.*;18import java.util.*;19public class Launcher {20 public static void main(String[] args) throws IOException {21 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));22 String input = in.readLine();23 System.out.println(input);24 }25}

Full Screen

Full Screen

Context

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cmd := exec.Command("java", "-cp", "C:\\Users\\user\\Desktop\\", "launcher")4 err := cmd.Start()5 if err != nil {6 fmt.Println(err)7 os.Exit(1)8 }9 fmt.Println("Waiting for command to finish...")10 err = cmd.Wait()11 fmt.Println("Command finished with error: ", err)12 time.Sleep(3 * time.Second)13}14import java.io.IOException;15import java.io.InputStream;16import java.io.OutputStream;17import java.io.PrintWriter;18import java.io.StringWriter;19import java.io.Writer;20import java.util.ArrayList;21import java.util.Arrays;22import java.util.List;23import java.util.Scanner;24import java.util.concurrent.TimeUnit;25import java.util.concurrent.TimeoutException;26import java.util.concurrent.atomic.AtomicBoolean;27import java.util.concurrent.atomic.AtomicReference;28import java.util.function.Consumer;29import java.util.stream.Collectors;30import java.util.stream.Stream;31import java.util.stream.StreamSupport;32public class launcher {33 public static void main(String[] args) throws Exception {34 Context context = new Context();35 context.setCommand("C:\\Users\\user\\Desktop\\test.exe");36 context.setArguments(Arrays.asList("arg1", "arg2"));37 context.setWorkingDirectory("C:\\Users\\user\\Desktop\\");38 context.setEnvironmentVariables(Arrays.asList("PATH=C:\\Users\\user\\Desktop\\"));39 context.setRedirectErrorStream(true);40 context.setRedirectStandardInput(true);41 context.setRedirectStandardOutput(true);42 context.setRedirectStandardError(true);43 context.setWaitForExit(true);44 context.setWaitForExitTimeout(3000);45 context.execute();46 }47}48import java.io.IOException;49import java.io.InputStream;50import java.io.OutputStream;51import java.io.PrintWriter;52import java.io.StringWriter;53import java.io.Writer;54import java.util.ArrayList;55import java.util.Arrays;56import java.util.List;57import java.util.Scanner;58import java.util.concurrent.TimeUnit;59import java.util.concurrent.TimeoutException;60import java.util.concurrent.atomic.AtomicBoolean;61import java.util.concurrent.atomic.AtomicReference;62import java.util.function.Consumer;63import java.util.stream.Collectors;

Full Screen

Full Screen

Context

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 app := cli.NewApp()4 nameFlag := cli.StringFlag{5 }6 app.Flags = []cli.Flag{nameFlag}7 app.Action = func(c *cli.Context) error {8 name := c.String("name")9 fmt.Printf("Hello %s!10 }11 app.Run(os.Args)12}13AUTHOR(S):14 --name value, -n value The name to be greeted (default: "World")15 --help, -h show help (default: false)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful