Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the appium:deviceName capability to find the specific browser #1305

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Caps struct {
W3CVersion string `json:"browserVersion,omitempty"`
Platform string `json:"platform,omitempty"`
W3CPlatform string `json:"platformName,omitempty"`
W3CDeviceName string `json:"appium:deviceName,omitempty"`
ScreenResolution string `json:"screenResolution,omitempty"`
Skin string `json:"skin,omitempty"`
VNC bool `json:"enableVNC,omitempty"`
Expand Down Expand Up @@ -47,6 +48,9 @@ func (c *Caps) ProcessExtensionCapabilities() {
if c.W3CPlatform != "" {
c.Platform = c.W3CPlatform
}
if c.W3CDeviceName != "" {
c.DeviceName = c.W3CDeviceName
}

if c.ExtensionCapabilities != nil {
mergo.Merge(c, *c.ExtensionCapabilities, mergo.WithOverride) //We probably need to handle returned error
Expand All @@ -58,7 +62,10 @@ func (c *Caps) BrowserName() string {
if browserName != "" {
return browserName
}
return c.DeviceName
if c.DeviceName != "" {
return c.DeviceName
}
return c.W3CDeviceName
}

// Container - container information
Expand Down
29 changes: 29 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func TestProcessExtensionCapabilities(t *testing.T) {
capsJson := `{
"version": "57.0",
"browserName": "firefox",
"appium:deviceName": "android",
"selenoid:options": {
"name": "ExampleTestName",
"enableVNC": true,
Expand All @@ -206,6 +207,7 @@ func TestProcessExtensionCapabilities(t *testing.T) {
caps.ProcessExtensionCapabilities()
AssertThat(t, caps.Name, EqualTo{"firefox"})
AssertThat(t, caps.Version, EqualTo{"57.0"})
AssertThat(t, caps.DeviceName, EqualTo{"android"})
AssertThat(t, caps.TestName, EqualTo{"ExampleTestName"})
AssertThat(t, caps.VNC, EqualTo{true})
AssertThat(t, caps.VideoFrameRate, EqualTo{uint16(24)})
Expand Down Expand Up @@ -250,3 +252,30 @@ func TestSumUsedTotalGreaterThanPending(t *testing.T) {
AssertThat(t, queue.Pending(), EqualTo{0})
AssertThat(t, queue.Used(), EqualTo{2})
}

func TestBrowserName(t *testing.T) {
var caps session.Caps

var capsJson = `{
"appium:deviceName": "iPhone 7"
}`
err := json.Unmarshal([]byte(capsJson), &caps)
AssertThat(t, err, Is{nil})
AssertThat(t, caps.BrowserName(), EqualTo{"iPhone 7"})

capsJson = `{
"deviceName": "android 11"
}`
err = json.Unmarshal([]byte(capsJson), &caps)
AssertThat(t, err, Is{nil})
AssertThat(t, caps.BrowserName(), EqualTo{"android 11"})

capsJson = `{
"deviceName": "android 11",
"appium:deviceName": "iPhone 7",
"browserName": "firefox"
}`
err = json.Unmarshal([]byte(capsJson), &caps)
AssertThat(t, err, Is{nil})
AssertThat(t, caps.BrowserName(), EqualTo{"firefox"})
}