From 45f472fe04cb9715dc5312563cf85dc9d53e51ec Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Sun, 26 Nov 2017 09:28:08 +0300 Subject: [PATCH] Renamed videoSize to videoScreenSize (related to #255) --- docs/log-files.adoc | 1 + docs/special-capabilities.adoc | 2 +- selenoid.go | 18 +++++++++--------- selenoid_test.go | 12 ++++++------ service/docker.go | 12 ++++++------ session/session.go | 2 +- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/docs/log-files.adoc b/docs/log-files.adoc index d5b62ffc..27dab8e5 100644 --- a/docs/log-files.adoc +++ b/docs/log-files.adoc @@ -42,6 +42,7 @@ The following statuses are available: | BAD_JSON_FORMAT | User request does not contain valid Selenium data | BAD_SCREEN_RESOLUTION | User requested to set wrong custom screen resolution | BAD_TIMEZONE | User requested to set wrong custom time zone inside container +| BAD_VIDEO_SCREEN_SIZE | User requested to capture video with wrong screen size | CLIENT_DISCONNECTED | User disconnected and session was interrupted | CONTAINER_LOGS | User requested container logs | CONTAINER_LOGS_ERROR | User requested container logs diff --git a/docs/special-capabilities.adoc b/docs/special-capabilities.adoc index 161113f8..e8d570cb 100644 --- a/docs/special-capabilities.adoc +++ b/docs/special-capabilities.adoc @@ -53,7 +53,7 @@ It is important to add `mp4` file extension. * By default the entire screen picture is being recorded. Specifying `screenResolution` capability changes recorded video size (width and height) accordingly. You can override video size by passing a capability: + ``` -videoSize: "1024x768" +videoScreenSize: "1024x768" ``` + If video size is less than actual browser screen size - only part of the screen fitting into specified size will be visible (measured from the left up corner). diff --git a/selenoid.go b/selenoid.go index 819c66f6..871a9e0c 100644 --- a/selenoid.go +++ b/selenoid.go @@ -144,14 +144,14 @@ func create(w http.ResponseWriter, r *http.Request) { return } browser.Caps.ScreenResolution = resolution - videoSize, err := getVideoSize(browser.Caps.VideoSize, resolution) + videoScreenSize, err := getVideoScreenSize(browser.Caps.VideoScreenSize, resolution) if err != nil { - log.Printf("[%d] [BAD_VIDEO_SIZE] [%s] [%s]\n", requestId, quota, browser.Caps.VideoSize) + log.Printf("[%d] [BAD_VIDEO_SCREEN_SIZE] [%s] [%s]\n", requestId, quota, browser.Caps.VideoScreenSize) jsonError(w, err.Error(), http.StatusBadRequest) queue.Drop() return } - browser.Caps.VideoSize = videoSize + browser.Caps.VideoScreenSize = videoScreenSize needToRenameVideo := false if browser.Caps.Video && browser.Caps.VideoName == "" { needToRenameVideo = true @@ -308,14 +308,14 @@ func shortenScreenResolution(screenResolution string) string { return fullFormat.FindStringSubmatch(screenResolution)[1] } -func getVideoSize(videoSize string, screenResolution string) (string, error) { - if videoSize != "" { - if shortFormat.MatchString(videoSize) { - return videoSize, nil +func getVideoScreenSize(videoScreenSize string, screenResolution string) (string, error) { + if videoScreenSize != "" { + if shortFormat.MatchString(videoScreenSize) { + return videoScreenSize, nil } return "", fmt.Errorf( - "Malformed videoSize capability: %s. Correct format is WxH (1920x1080).", - videoSize, + "Malformed videoScreenSize capability: %s. Correct format is WxH (1920x1080).", + videoScreenSize, ) } return shortenScreenResolution(screenResolution), nil diff --git a/selenoid_test.go b/selenoid_test.go index fd557f0e..d93b9156 100644 --- a/selenoid_test.go +++ b/selenoid_test.go @@ -94,22 +94,22 @@ func TestMalformedScreenResolutionCapability(t *testing.T) { AssertThat(t, queue.Used(), EqualTo{0}) } -func TestGetVideoSizeFromCapability(t *testing.T) { - res, err := getVideoSize("1024x768", "anything") +func TestGetVideoScreenSizeFromCapability(t *testing.T) { + res, err := getVideoScreenSize("1024x768", "anything") AssertThat(t, err, Is{nil}) AssertThat(t, res, EqualTo{"1024x768"}) } -func TestDetermineVideoSizeFromScreenResolution(t *testing.T) { - res, err := getVideoSize("", "1024x768x24") +func TestDetermineVideoScreenSizeFromScreenResolution(t *testing.T) { + res, err := getVideoScreenSize("", "1024x768x24") AssertThat(t, err, Is{nil}) AssertThat(t, res, EqualTo{"1024x768"}) } -func TestMalformedVideoSizeCapability(t *testing.T) { +func TestMalformedVideoScreenSizeCapability(t *testing.T) { manager = &BrowserNotFound{} - rsp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte(`{"desiredCapabilities":{"videoSize":"bad-size"}}`))) + rsp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte(`{"desiredCapabilities":{"videoScreenSize":"bad-size"}}`))) AssertThat(t, err, Is{nil}) AssertThat(t, rsp, Code{http.StatusBadRequest}) diff --git a/service/docker.go b/service/docker.go index 3496180f..f1625e21 100644 --- a/service/docker.go +++ b/service/docker.go @@ -16,13 +16,13 @@ import ( "github.com/docker/docker/api/types/strslice" "github.com/docker/docker/client" "github.com/docker/go-connections/nat" - "strings" "os" + "strings" ) const ( - comma = "," - sysAdmin = "SYS_ADMIN" + comma = "," + sysAdmin = "SYS_ADMIN" overrideVideoOutputDir = "OVERRIDE_VIDEO_OUTPUT_DIR" ) @@ -276,9 +276,9 @@ func startVideoContainer(ctx context.Context, cl *client.Client, requestId uint6 videoContainerStartTime := time.Now() videoContainerImage := environ.VideoContainerImage env := []string{fmt.Sprintf("FILE_NAME=%s", caps.VideoName)} - videoSize := caps.VideoSize - if videoSize != "" { - env = append(env, fmt.Sprintf("VIDEO_SIZE=%s", videoSize)) + videoScreenSize := caps.VideoScreenSize + if videoScreenSize != "" { + env = append(env, fmt.Sprintf("VIDEO_SIZE=%s", videoScreenSize)) } log.Printf("[%d] [CREATING_VIDEO_CONTAINER] [%s]\n", requestId, videoContainerImage) videoContainer, err := cl.ContainerCreate(ctx, diff --git a/session/session.go b/session/session.go index 56df654d..3f3ec4ca 100644 --- a/session/session.go +++ b/session/session.go @@ -13,7 +13,7 @@ type Caps struct { VNC bool `json:"enableVNC"` Video bool `json:"enableVideo"` VideoName string `json:"videoName"` - VideoSize string `json:"videoSize"` + VideoScreenSize string `json:"videoScreenSize"` TestName string `json:"name"` TimeZone string `json:"timeZone"` ContainerHostname string `json:"containerHostname"`