{"action":"created","issue":{"url":"https://api.github.com/repos/DATA-DOG/godog/issues/77","repository_url":"https://api.github.com/repos/DATA-DOG/godog","labels_url":"https://api.github.com/repos/DATA-DOG/godog/issues/77/labels{/name}","comments_url":"https://api.github.com/repos/DATA-DOG/godog/issues/77/comments","events_url":"https://api.github.com/repos/DATA-DOG/godog/issues/77/events","html_url":"https://github.com/DATA-DOG/godog/issues/77","id":224647395,"number":77,"title":"Selenium WebDriver","user":{"login":"llonchj","id":355646,"avatar_url":"https://avatars0.githubusercontent.com/u/355646?v=3","gravatar_id":"","url":"https://api.github.com/users/llonchj","html_url":"https://github.com/llonchj","followers_url":"https://api.github.com/users/llonchj/followers","following_url":"https://api.github.com/users/llonchj/following{/other_user}","gists_url":"https://api.github.com/users/llonchj/gists{/gist_id}","starred_url":"https://api.github.com/users/llonchj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/llonchj/subscriptions","organizations_url":"https://api.github.com/users/llonchj/orgs","repos_url":"https://api.github.com/users/llonchj/repos","events_url":"https://api.github.com/users/llonchj/events{/privacy}","received_events_url":"https://api.github.com/users/llonchj/received_events","type":"User","site_admin":false},"labels":[{"id":592998761,"url":"https://api.github.com/repos/DATA-DOG/godog/labels/Question","name":"Question","color":"5319e7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-04-27T01:57:25Z","updated_at":"2017-04-27T08:50:08Z","closed_at":null,"body":"Hi,\r\n\r\nI am using godog with selenium to test browser interaction. In order to access webdriver I use something like:\r\n\r\n```go\r\ntype WebDriver struct {\r\n\tselenium.WebDriver\r\n}\r\n\r\nfunc (w *WebDriver) iAmAnAnonymousUser() error {\r\n\treturn w.DeleteAllCookies()\r\n}\r\n\r\nfunc FeatureContext(s *godog.Suite) {\r\n\twd, err := NewBrowser()\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\r\n\ts.Step(`^I am a anonymous user$`, wd.iAmAnAnonymousUser)\r\n\r\n\ts.AfterSuite(func() {\r\n\t\twd.Quit()\r\n\t\twd = nil\r\n\t})\r\n}\r\n```\r\n\r\nIn this scenario, only a browser/webdriver (wd) instance is allowed per suite. \r\n\r\nI would like to use concurrency using a different webdriver instance on each feature. What will be the best practice?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/DATA-DOG/godog/issues/comments/297653314","html_url":"https://github.com/DATA-DOG/godog/issues/77#issuecomment-297653314","issue_url":"https://api.github.com/repos/DATA-DOG/godog/issues/77","id":297653314,"user":{"login":"l3pp4rd","id":132389,"avatar_url":"https://avatars3.githubusercontent.com/u/132389?v=3","gravatar_id":"","url":"https://api.github.com/users/l3pp4rd","html_url":"https://github.com/l3pp4rd","followers_url":"https://api.github.com/users/l3pp4rd/followers","following_url":"https://api.github.com/users/l3pp4rd/following{/other_user}","gists_url":"https://api.github.com/users/l3pp4rd/gists{/gist_id}","starred_url":"https://api.github.com/users/l3pp4rd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/l3pp4rd/subscriptions","organizations_url":"https://api.github.com/users/l3pp4rd/orgs","repos_url":"https://api.github.com/users/l3pp4rd/repos","events_url":"https://api.github.com/users/l3pp4rd/events{/privacy}","received_events_url":"https://api.github.com/users/l3pp4rd/received_events","type":"User","site_admin":false},"created_at":"2017-04-27T08:50:08Z","updated_at":"2017-04-27T08:50:08Z","body":"The best practice is to have a suite context with all the state in a separate structs, which has all the steps as functions bind to that struct.\r\n\r\n``` go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"sync\"\r\n\t\"time\"\r\n\r\n\t\"github.com/DATA-DOG/godog\"\r\n)\r\n\r\ntype selenium int64 // just to simulate selenium instance\r\n\r\nvar pool = sync.Pool{\r\n\tNew: func() interface{} {\r\n\t\treturn selenium(time.Now().UnixNano()) // should create NewBrowser\r\n\t},\r\n}\r\n\r\ntype webContext struct {\r\n\twd selenium\r\n}\r\n\r\nfunc (c *webContext) passingStep() error {\r\n\tfmt.Println(\"using browser:\", c.wd)\r\n\treturn nil\r\n}\r\n\r\nfunc FeatureContext(s *godog.Suite) {\r\n\tcontext := &webContext{}\r\n\r\n\ts.Step(`^passing step$`, context.passingStep)\r\n\r\n\ts.BeforeScenario(func(interface{}) {\r\n\t\tcontext.wd = pool.Get().(selenium)\r\n\t})\r\n\ts.AfterScenario(func(interface{}, error) {\r\n\t\tpool.Put(context.wd)\r\n\t})\r\n}\r\n```\r\n\r\nI used a simple **selenium** type in order to show you, that it is a different reference.\r\n\r\n![2017-04-27-114613](https://cloud.githubusercontent.com/assets/132389/25475438/68cf8c6a-2b3f-11e7-9022-f95837b00b8a.png)\r\n\r\nYou can see in the screenshot what are the results when running concurrently. There is no **BeforeFeature** hook though, forgot about it. But Before and After scenario are good hooks for this kind of task, since you should isolate global state for each scenario."}}
{"actor":{"display_login":"l3pp4rd"}}