github.com/bazelbuild/rules_webtesting@v0.2.0/go/wtl/environment/sauce/sauce.go (about) 1 // Copyright 2016 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package sauce provides a simple environment for accessing a SauceLabs browser. 16 // It depends on environment variables SAUCE_USERNAME and SAUCE_ACCESS_KEY being defined. 17 // TODO(DrMarcII): Add SauceConnect support. 18 package sauce 19 20 import ( 21 "context" 22 "os" 23 24 "github.com/bazelbuild/rules_webtesting/go/metadata" 25 "github.com/bazelbuild/rules_webtesting/go/wtl/diagnostics" 26 "github.com/bazelbuild/rules_webtesting/go/wtl/environment" 27 ) 28 29 const ( 30 name = "Sauce WebDriver Environment" 31 ) 32 33 type sauce struct { 34 *environment.Base 35 address string 36 } 37 38 // NewEnv creates a new environment that uses an externally started Selenium Server. 39 func NewEnv(m *metadata.Metadata, d diagnostics.Diagnostics) (environment.Env, error) { 40 address := os.ExpandEnv("http://${SAUCE_USERNAME}:${SAUCE_ACCESS_KEY}@ondemand.saucelabs.com/wd/hub/") 41 42 base, err := environment.NewBase(name, m, d) 43 if err != nil { 44 return nil, err 45 } 46 47 return &sauce{ 48 Base: base, 49 address: address, 50 }, nil 51 } 52 53 // WDAddress returns the user-provided selenium address. 54 func (s *sauce) WDAddress(context.Context) string { 55 return s.address 56 }