Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1305 from BorisOsipov/fix_appium_device_name
Browse files Browse the repository at this point in the history
Use the appium:deviceName capability to find the specific browser
  • Loading branch information
vania-pooh authored Feb 4, 2023
2 parents df4446e + e3e31bc commit 1176ec6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
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"})
}

0 comments on commit 1176ec6

Please sign in to comment.