How to use testClipboard method of main Package

Best Selenoid code snippet using main.testClipboard

selenoid_test.go

Source:selenoid_test.go Github

copy

Full Screen

...679 AssertThat(t, err, Is{nil})680 AssertThat(t, rsp, Code{http.StatusNotFound})681}682func TestClipboard(t *testing.T) {683 testClipboard(t, func(sessionId string) string {684 return fmt.Sprintf("/clipboard/%s", sessionId)685 })686}687func TestClipboardProtocolExtension(t *testing.T) {688 testClipboard(t, func(sessionId string) string {689 return fmt.Sprintf("/wd/hub/session/%s/aerokube/clipboard", sessionId)690 })691}692func testClipboard(t *testing.T, path func(string) string) {693 manager = &HTTPTest{Handler: Selenium()}694 resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}")))695 AssertThat(t, err, Is{nil})696 var sess map[string]string697 AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}})698 rsp, err := http.Get(With(srv.URL).Path(path(sess["sessionId"])))699 AssertThat(t, err, Is{nil})700 AssertThat(t, rsp, Code{http.StatusOK})701 data, err := io.ReadAll(rsp.Body)702 AssertThat(t, err, Is{nil})703 AssertThat(t, string(data), EqualTo{"test-clipboard-value"})704 rsp, err = http.Post(With(srv.URL).Path(path(sess["sessionId"])), "text/plain", bytes.NewReader([]byte("any-data")))705 AssertThat(t, err, Is{nil})706 AssertThat(t, rsp, Code{http.StatusOK})...

Full Screen

Full Screen

systray_test.go

Source:systray_test.go Github

copy

Full Screen

1package systray2import (3 "math/rand"4 "strconv"5 "testing"6 "time"7 "github.com/getlantern/systray"8 "github.com/prashantgupta24/go-clip/clip"9 "github.com/stretchr/testify/assert"10 "github.com/stretchr/testify/suite"11)12type ClipTestSuite struct {13 suite.Suite14}15func (suite *ClipTestSuite) SetupTest() {16 clipboardInstance = nil17 initInstance()18}19func TestSuite(t *testing.T) {20 suite.Run(t, new(ClipTestSuite))21}22func (suite *ClipTestSuite) TestInit() {23 t := suite.T()24 assert.NotNil(t, clipboardInstance)25 initInstance()26 assert.Equal(t, clipboardInstance.activeSlots, 0)27}28func (suite *ClipTestSuite) TestInitializeClipBoard() {29 t := suite.T()30 initializeClipBoard()31 assert.Equal(t, 10, clipboardInstance.activeSlots)32}33func (suite *ClipTestSuite) TestAddSlots() {34 t := suite.T()35 assert.Len(t, clipboardInstance.menuItemArray, 0)36 addSlots(20, clipboardInstance)37 assert.Len(t, clipboardInstance.menuItemArray, 20)38 assert.Equal(t, getActiveSlots(clipboardInstance), 20)39 assert.Equal(t, 20, clipboardInstance.activeSlots)40 addSlots(20, clipboardInstance)41 assert.Len(t, clipboardInstance.menuItemArray, 40)42 assert.Equal(t, getActiveSlots(clipboardInstance), 40)43 assert.Equal(t, 40, clipboardInstance.activeSlots)44}45func (suite *ClipTestSuite) TestChangeSlots() {46 t := suite.T()47 assert.Len(t, clipboardInstance.menuItemArray, 0)48 addSlots(20, clipboardInstance)49 assert.Len(t, clipboardInstance.menuItemArray, 20)50 assert.Equal(t, 20, clipboardInstance.activeSlots)51 for i := 0; i < 20; i++ {52 changetTo := rand.Intn(20) + 153 changeActiveSlots(changetTo, clipboardInstance)54 assert.Equal(t, changetTo, getActiveSlots(clipboardInstance))55 }56}57func (suite *ClipTestSuite) TestObfuscateVal() {58 t := suite.T()59 menuItem := menuItem{60 instance: &systray.MenuItem{},61 subMenuItems: make(map[subMenu]*systray.MenuItem),62 }63 menuItem.subMenuItems[obfuscateMenu] = &systray.MenuItem{}64 //test165 clipboardInstance.menuItemToVal[menuItem.instance] = "test_value"66 obfuscateVal(clipboardInstance, menuItem)67 assert.Equal(t, "test******", getTitle(menuItem))68 assert.Equal(t, "test******", getToolTip(menuItem))69 assert.True(t, menuItem.subMenuItems[obfuscateMenu].Checked())70 //test271 clipboardInstance.menuItemToVal[menuItem.instance] = "test"72 obfuscateVal(clipboardInstance, menuItem)73 assert.Equal(t, "test", getTitle(menuItem))74 assert.Equal(t, "test", getToolTip(menuItem))75 assert.True(t, menuItem.subMenuItems[obfuscateMenu].Checked())76 //test377 clipboardInstance.menuItemToVal[menuItem.instance] = "this_is_a_big_value"78 obfuscateVal(clipboardInstance, menuItem)79 assert.Equal(t, "this***************", getTitle(menuItem))80 assert.Equal(t, "this***************", getToolTip(menuItem))81 assert.True(t, menuItem.subMenuItems[obfuscateMenu].Checked())82}83func (suite *ClipTestSuite) TestAcceptVal() {84 t := suite.T()85 addSlots(20, clipboardInstance)86 for i := 0; i < 20; i++ {87 menuItem := clipboardInstance.menuItemArray[i]88 val1 := "test_message_" + strconv.Itoa(i)89 assert.Equal(t, "", getTitle(menuItem))90 assert.Equal(t, "(empty slot)", getToolTip(menuItem))91 assert.False(t, clipboardInstance.valExistsMap[val1])92 assert.NotContains(t, clipboardInstance.menuItemToVal, menuItem.instance)93 assert.True(t, menuItem.subMenuItems[obfuscateMenu].Disabled())94 assert.True(t, menuItem.subMenuItems[pinMenu].Disabled())95 acceptVal(clipboardInstance, menuItem, val1)96 assert.Equal(t, val1, getTitle(menuItem))97 assert.Equal(t, val1, getToolTip(menuItem))98 assert.True(t, clipboardInstance.valExistsMap[val1])99 assert.Contains(t, clipboardInstance.menuItemToVal, menuItem.instance)100 assert.Equal(t, val1, clipboardInstance.menuItemToVal[menuItem.instance])101 assert.False(t, menuItem.subMenuItems[obfuscateMenu].Disabled())102 assert.False(t, menuItem.subMenuItems[pinMenu].Disabled())103 }104}105func (suite *ClipTestSuite) TestSubstituteMenuItem() {106 t := suite.T()107 addSlots(20, clipboardInstance)108 menuItem := menuItem{109 instance: &systray.MenuItem{},110 subMenuItems: make(map[subMenu]*systray.MenuItem),111 }112 menuItem.subMenuItems[pinMenu] = &systray.MenuItem{}113 menuItem.subMenuItems[obfuscateMenu] = &systray.MenuItem{}114 menuItem.subMenuItems[obfuscateMenu].Check()115 existingMenuItem := getExistingSlotToReplace()116 valNew := "test_value_new"117 valExisting := "test_value_existing"118 acceptVal(clipboardInstance, menuItem, valNew)119 acceptVal(clipboardInstance, existingMenuItem, valExisting)120 assert.NotNil(t, existingMenuItem)121 assert.False(t, existingMenuItem.instance.Checked())122 assert.False(t, menuItem.instance.Checked())123 assert.Equal(t, valNew, getTitle(menuItem))124 assert.Equal(t, valNew, getToolTip(menuItem))125 assert.Equal(t, valExisting, getToolTip(existingMenuItem))126 assert.Equal(t, valExisting, getToolTip(existingMenuItem))127 substituteMenuItem(clipboardInstance, menuItem)128 assert.True(t, existingMenuItem.instance.Checked())129 assert.False(t, menuItem.instance.Checked())130 assert.Equal(t, valExisting, getTitle(menuItem))131 assert.Equal(t, valExisting, getToolTip(menuItem))132 assert.Equal(t, "test**********", getTitle(existingMenuItem))133 assert.Equal(t, "test**********", getToolTip(existingMenuItem))134}135func (suite *ClipTestSuite) TestSlotChannels() {136 t := suite.T()137 addSlots(20, clipboardInstance)138 for i := 0; i < clipboardInstance.activeSlots; i++ {139 menuItem := clipboardInstance.menuItemArray[i]140 obfuscateMenu := menuItem.subMenuItems[obfuscateMenu]141 //obfuscate142 obfuscateMenu.ClickedCh <- struct{}{}143 time.Sleep(time.Millisecond * 10)144 clipboardInstance.mutex.RLock()145 assert.True(t, obfuscateMenu.Checked())146 clipboardInstance.mutex.RUnlock()147 //unobfuscate148 obfuscateMenu.ClickedCh <- struct{}{}149 time.Sleep(time.Millisecond * 10)150 clipboardInstance.mutex.RLock()151 assert.False(t, obfuscateMenu.Checked())152 clipboardInstance.mutex.RUnlock()153 //pin154 existingMenuItem := getExistingSlotToReplace()155 pinMenuOrg := menuItem.subMenuItems[pinMenu]156 pinMenuOrg.ClickedCh <- struct{}{}157 time.Sleep(time.Millisecond * 10)158 clipboardInstance.mutex.RLock()159 assert.NotNil(t, existingMenuItem)160 assert.True(t, existingMenuItem.instance.Checked())161 if i != 0 { //first slot gets replaced by itself162 assert.False(t, menuItem.instance.Checked())163 }164 clipboardInstance.mutex.RUnlock()165 //unpin166 existingPinMenu := existingMenuItem.subMenuItems[pinMenu]167 existingPinMenu.ClickedCh <- struct{}{}168 time.Sleep(time.Millisecond * 10)169 clipboardInstance.mutex.RLock()170 assert.False(t, existingMenuItem.instance.Checked())171 clipboardInstance.mutex.RUnlock()172 }173}174func getExistingSlotToReplace() menuItem {175 for i := 0; i < clipboardInstance.activeSlots; i++ {176 existingMenuItem := clipboardInstance.menuItemArray[i]177 if !existingMenuItem.instance.Disabled() && !existingMenuItem.instance.Checked() {178 return existingMenuItem179 }180 }181 return menuItem{}182}183func (suite *ClipTestSuite) TestClearSlots() {184 t := suite.T()185 addSlots(20, clipboardInstance)186 clearSlots(clipboardInstance.menuItemArray)187 assert.Equal(t, 0, clipboardInstance.nextMenuItemIndex)188}189func (suite *ClipTestSuite) TestTruncateVal() {190 t := suite.T()191 val := "this_will_be_truncated_into_something_small"192 truncVal := truncateVal(clipboardInstance, val)193 assert.Equal(t, val[:clipboardInstance.truncateLength]+"... ("+strconv.Itoa(len(val))+" chars)", truncVal)194}195func (suite *ClipTestSuite) TestClickVal() {196 t := suite.T()197 changes := make(chan string, 1)198 stopCh := make(chan struct{})199 go clip.Monitor(time.Millisecond*50, stopCh, changes)200 addSlots(1, clipboardInstance)201 menuItem := clipboardInstance.menuItemArray[0].instance202 for i := 0; i < 10; i++ {203 val := "test_val_" + strconv.Itoa(i)204 clipboardInstance.menuItemToVal[menuItem] = val205 menuItem.ClickedCh <- struct{}{}206 value := <-changes207 assert.Equal(t, val, value)208 }209}210func (suite *ClipTestSuite) TestClipboard() {211 t := suite.T()212 addSlots(20, clipboardInstance)213 assert.Len(t, clipboardInstance.menuItemArray, clipboardInstance.activeSlots)214 changes := make(chan string, 10)215 stopCh := make(chan struct{})216 go monitorClipboard(clipboardInstance, stopCh, changes)217 rand.Seed(time.Now().UnixNano())218 for i := 0; i < 100; i++ {219 // v1 := len(clipboardInstance.menuItemToVal)220 // v2 := len(clipboardInstance.valExistsMap)221 // assert.Len(t, clipboardInstance.menuItemToVal, min(i, clipboardInstance.activeSlots))222 // assert.Len(t, clipboardInstance.valExistsMap, min(i, clipboardInstance.activeSlots))223 changes <- "hello" + strconv.Itoa(i)224 time.Sleep(time.Millisecond * 10)225 // assert.Len(t, clipboardInstance.menuItemToVal, v1+1)226 // assert.Len(t, clipboardInstance.valExistsMap, v2+1)227 clipboardInstance.mutex.RLock()228 assert.Contains(t, clipboardInstance.valExistsMap, "hello"+strconv.Itoa(i))229 clipboardInstance.mutex.RUnlock()230 if i%5 == 0 && i != 0 {231 time.Sleep(time.Millisecond * 10)232 changetTo := rand.Intn(20) + 1233 // fmt.Println("pclipboardInstance.nextMenuItemIndex : ", clipboardInstance.nextMenuItemIndex)234 // fmt.Println("changed to : ", changetTo)235 changeActiveSlots(changetTo, clipboardInstance)236 assert.Equal(t, changetTo, getActiveSlots(clipboardInstance))237 // fmt.Println("aclipboardInstance.nextMenuItemIndex : ", clipboardInstance.nextMenuItemIndex)238 }239 }240}241func getActiveSlots(clipboard *clipboard) int {242 activeSlots := 0243 for _, menuItem := range clipboardInstance.menuItemArray {244 if !menuItem.instance.Disabled() {245 activeSlots++246 }247 }248 return activeSlots249}250// uncomment for visual testing251// func TestMain(m *testing.M) {252// timeToSleep := time.Second //change accordingly253// initInstance()254// systray.Run(func() {255// systray.SetTemplateIcon(icon.Data, icon.Data)256// systray.SetTooltip("Clipboard")257// mQuitOrig := systray.AddMenuItem("Quit", "Quit the app")258// go func() {259// <-mQuitOrig.ClickedCh260// fmt.Println("Requesting quit")261// systray.Quit()262// fmt.Println("Finished quitting")263// }()264// // We can manipulate the systray in other goroutines265// configureMenu := systray.AddMenuItem("Configuration", "Configuration")266// slotsMenu := configureMenu.AddSubMenuItem("slotsMenu", "SubMenu Test (middle)")267// slots5 := slotsMenu.AddSubMenuItem("5", "5")268// slots10 := slotsMenu.AddSubMenuItem("10", "10")269// slots20 := slotsMenu.AddSubMenuItem("20", "20")270// clearMenu := configureMenu.AddSubMenuItem("Clear", "Clear")271// addSlots(20, clipboardInstance)272// changes := make(chan string, 10)273// stopCh := make(chan struct{})274// go monitorClipboard(clipboardInstance, stopCh, changes)275// go func() {276// for {277// select {278// case <-slots5.ClickedCh:279// // fmt.Println("changed to 5")280// changeActiveSlots(5, clipboardInstance)281// case <-slots10.ClickedCh:282// // fmt.Println("changed to 10")283// changeActiveSlots(10, clipboardInstance)284// case <-slots20.ClickedCh:285// // fmt.Println("changed to 20")286// changeActiveSlots(20, clipboardInstance)287// case <-clearMenu.ClickedCh:288// // fmt.Println("clear")289// clearSlots(clipboardInstance.menuItemArray)290// }291// }292// }()293// for i := 0; i < 100; i++ {294// // // assert.Len(, clipboardInstance.menuItemToVal, i)295// // // assert.Len(t, clipboardInstance.valExistsMap, i)296// time.Sleep(timeToSleep)297// changes <- "hello" + strconv.Itoa(i)298// if i%5 == 0 && i != 0 {299// time.Sleep(time.Millisecond * 10)300// changetTo := rand.Intn(15) + 5301// log.Println("pclipboardInstance.nextMenuItemIndex : ", clipboardInstance.nextMenuItemIndex)302// log.Println("changed to : ", changetTo)303// changeActiveSlots(changetTo, clipboardInstance)304// // assert.Equal(t, changetTo, getActiveSlots(clipboardInstance))305// log.Println("aclipboardInstance.nextMenuItemIndex : ", clipboardInstance.nextMenuItemIndex)306// // time.Sleep(time.Millisecond * 10)307// }308// }309// }, func() {})310// }...

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.

Run Selenoid automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful