capybara-wsl 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/README.md +44 -0
- data/capybara-wsl.gemspec +17 -0
- data/lib/capybara-wsl.rb +3 -0
- data/lib/capybara/wsl.rb +55 -0
- data/lib/capybara/wsl/distros.rb +16 -0
- data/lib/capybara/wsl/dsl.rb +13 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 677b081aa2669018eacb29b107de53fed0b6504a3e68484d193446084e5392a5
|
4
|
+
data.tar.gz: 782cf20c5c5ec1623ae71c3d3410af23b12eebe231bf7cfbd3b4927e9eac29f6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c05a9ce925c9ba369ec21eb13099d6d5de64a9924cabcee79dfbafe74d142445869bf4cc46a981a3495d88d6da1747edc7290925cf0d843bbe32eb12cae17fe8
|
7
|
+
data.tar.gz: 1a36d375e350a2d98680ce20b653648327e9a82e1cf07674e5f68f6c2326199d470d5804c2fffa0e387363f9f0d5962b8c32f596f644a2d0505346ed4418394c
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
CapybaraWSL
|
2
|
+
=======================
|
3
|
+
|
4
|
+
#### Allows you use open saved pages from WSL
|
5
|
+
|
6
|
+
Capybara's `save_and_open_page` and `save_and_open_screenshot` methods don't work properly in WSL. It saves pages/screenshots, but when it tries to open them via Launchy, it passes Linux path, which obviously wouldn't work in Windows browsers.
|
7
|
+
|
8
|
+
This gem modifies that path to include `wsl$` part so that it's understandable for Windows browsers.
|
9
|
+
|
10
|
+
### Installation
|
11
|
+
In your `Gemfile` add:
|
12
|
+
```
|
13
|
+
gem "capybara-wsl", git: "git@github.com:dersnek/capybara-wsl.git"
|
14
|
+
```
|
15
|
+
Then run `bundle install`.
|
16
|
+
|
17
|
+
Or via [specific_install](https://github.com/rdp/specific_install) gem if you don't want to clutter your `Gemfile`.
|
18
|
+
|
19
|
+
### Important note
|
20
|
+
In order for it to work, you have to add `$BROWSER` env variable.
|
21
|
+
###### Example for Firefox
|
22
|
+
In your `.bashrc` add:
|
23
|
+
```
|
24
|
+
export BROWSER='/mnt/c/Program Files/Mozilla Firefox/firefox.exe'
|
25
|
+
```
|
26
|
+
|
27
|
+
### Usage
|
28
|
+
Simply use
|
29
|
+
`save_and_open_page_wsl` or
|
30
|
+
`save_and_open_screenshot_wsl` instead of their normal versions.
|
31
|
+
|
32
|
+
If you installed via `gem install`:
|
33
|
+
Run `gem which capybara-wsl` in your console and copy output.
|
34
|
+
Use as:
|
35
|
+
```
|
36
|
+
require "copied output"
|
37
|
+
Capybara::WSL.save_and_open_page
|
38
|
+
Capybara::WSL.save_and_open_screenshot
|
39
|
+
```
|
40
|
+
|
41
|
+
CapybaraWSL converts page/screenshot path to WSL Ubuntu path by default. If you have another distro, please set the `distro` setting `Capybara::WSL.distro = :debian` to whichever distro you are using.
|
42
|
+
You can look up available distro keys in `Capybara::WSL::DISTROS`. You can also set `distro` to a string with exact folder name of your distro `Capybara::WSL.distro = "openSUSE-Leap-15-1"`.
|
43
|
+
|
44
|
+
Please tell me if some of those distro folder names in `Capybara::WSL::DISTROS` are incorrect, I don't really have a way to check it.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "capybara-wsl"
|
5
|
+
s.version = "0.2.0"
|
6
|
+
s.date = "2020-06-24"
|
7
|
+
s.summary = "WSL support for Capybara"
|
8
|
+
s.description = "Allows Capybara to open pages/screenshots in Windows browsers via Launchy."
|
9
|
+
s.authors = ["Mark Tityuk"]
|
10
|
+
s.email = "mark.tityuk@gmail.com"
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.homepage = "https://github.com/dersnek/capybara-wsl"
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.add_dependency "capybara", ">= 2.0"
|
16
|
+
s.add_dependency "launchy", ">= 2.0"
|
17
|
+
end
|
data/lib/capybara-wsl.rb
ADDED
data/lib/capybara/wsl.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "capybara"
|
4
|
+
require "capybara/dsl"
|
5
|
+
require_relative "wsl/distros"
|
6
|
+
require_relative "wsl/dsl"
|
7
|
+
|
8
|
+
module Capybara
|
9
|
+
module WSL
|
10
|
+
class CapybaraWSLError < StandardError; end
|
11
|
+
class DistroKeyNotSupported < CapybaraWSLError; end
|
12
|
+
|
13
|
+
def self.save_and_open_page(path = nil)
|
14
|
+
Capybara.current_session.save_page(path).tap do |s_path|
|
15
|
+
wsl_path = modify_path(s_path)
|
16
|
+
Capybara.current_session.send(:open_file, wsl_path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.save_and_open_screenshot(path = nil, **options)
|
21
|
+
Capybara.current_session.save_screenshot(path, options).tap do |s_path|
|
22
|
+
wsl_path = modify_path(s_path)
|
23
|
+
Capybara.current_session.send(:open_file, wsl_path)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.distro
|
28
|
+
@distro || :ubuntu
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.distro=(name)
|
32
|
+
if name.is_a?(Symbol) && DISTROS[name].nil?
|
33
|
+
raise(Capybara::WSL::DistroKeyNotSupported,
|
34
|
+
"This distro key is not supported. Please use supported key or pass a string with exact distro folder name.")
|
35
|
+
end
|
36
|
+
|
37
|
+
@distro = name
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def self.modify_path(path)
|
43
|
+
path.gsub "/home/", "file://///wsl$/#{distro_folder_name}/home/"
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.distro_folder_name
|
47
|
+
return distro if distro.is_a?(String)
|
48
|
+
|
49
|
+
DISTROS[distro]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Add WSL-relared methods to Capybara's DSL
|
55
|
+
Capybara::DSL.include Capybara::WSL::DSL
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
module WSL
|
5
|
+
DISTROS = {
|
6
|
+
alpine: "Alpine-WSL",
|
7
|
+
centos: "CentOS",
|
8
|
+
debian: "Debian",
|
9
|
+
fedors: "Fedora-Remix-for-WSL",
|
10
|
+
kali: "kali-linux",
|
11
|
+
opensuse: "openSUSE-Leap-15-1",
|
12
|
+
pengwin: "Pengwin",
|
13
|
+
ubuntu: "Ubuntu",
|
14
|
+
}.freeze
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capybara-wsl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Tityuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capybara
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: launchy
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
description: Allows Capybara to open pages/screenshots in Windows browsers via Launchy.
|
42
|
+
email: mark.tityuk@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- Gemfile
|
48
|
+
- README.md
|
49
|
+
- capybara-wsl.gemspec
|
50
|
+
- lib/capybara-wsl.rb
|
51
|
+
- lib/capybara/wsl.rb
|
52
|
+
- lib/capybara/wsl/distros.rb
|
53
|
+
- lib/capybara/wsl/dsl.rb
|
54
|
+
homepage: https://github.com/dersnek/capybara-wsl
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubygems_version: 3.1.2
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: WSL support for Capybara
|
77
|
+
test_files: []
|