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

Disable "tabs" permission #32

Merged
merged 2 commits into from
Sep 3, 2022
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea/
tests/drivers/
tests/.virtualenv
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Features
Running tests
---

Download drivers for Browsers and place them in tests/drivers folder.

For Chrome: https://chromedriver.chromium.org/capabilities
For Opera: https://github.com/operasoftware/operachromiumdriver

$ cd tests
$ virtualenv .virtualenv
$ source .virtualenv/bin/activate
Expand Down
Binary file added resources/promo_big.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion restman/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"64": "img/icon64.png"
},
"background": {"scripts": ["js/background.js"], "persistent": false},
"permissions": ["tabs", "http://*/", "http://*/*", "https://*/", "https://*/*", "storage"],
"permissions": ["http://*/", "http://*/*", "https://*/", "https://*/*", "storage"],
"browser_action": {
"default_icon": "img/icon32.png",
"default_title": "RestMan"
Expand Down
12 changes: 3 additions & 9 deletions tests/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,11 @@ def prepare_chrome(context):

b64ext = base64.b64encode(open(test_extension, 'rb').read())

capabilities = {
"goog:chromeOptions": {
"extensions": [b64ext],
},
"proxy": {
"proxyType": "system"
}
}
chrome_options = webdriver.ChromeOptions()
chrome_options.add_extension(test_extension)

# Create browser
context.browser = webdriver.Remote(context.service.service_url, capabilities)
context.browser = webdriver.Remote(context.service.service_url, options=chrome_options)

def before_all(context):
#prepare_chrome(context)
Expand Down
18 changes: 5 additions & 13 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
behave==1.2.5
decorator==3.4.2
enum34==1.0.4
flask>=1.0.0
itsdangerous==0.24
Jinja2>=2.10.1
MarkupSafe==0.23
parse==1.6.6
parse-type==0.3.4
selenium==3.141.0
six==1.9.0
werkzeug>=0.15.3
behave==1.2.6
selenium==4.4.3
Werkzeug==2.0.3
flask==2.1.3

# For testing
httpbin==0.2.1
httpbin==0.7.0
24 changes: 14 additions & 10 deletions tests/steps/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
def step_impl(context):
# Open history by focusing on the input and force a input event that
# even if the history was closed with ESC it will be shown.
context.browser.find_element_by_id('Url').send_keys("A", Keys.BACK_SPACE)
context.browser.find_element(By.ID, 'Url').send_keys("A", Keys.BACK_SPACE)
# Wait for modal to appear
WebDriverWait(context.browser, 10).until(
expected_conditions.visibility_of_element_located(
Expand All @@ -29,32 +29,36 @@ def step_impl(context):
given I open History dialog
''')
# Clear history and exit
context.browser.find_element_by_id('ClearHistory').click()
button = WebDriverWait(context.browser, 10).until(
expected_conditions.visibility_of_element_located(
(By.ID, 'ClearHistory')))
button.click()

ActionChains(context.browser).send_keys(Keys.ESCAPE).perform()
time.sleep(0.5)

@step('url "{url}" with method "{method}" it\'s in the history')
def step_impl(context, url, method):
history = context.browser.find_element_by_id("HistoryPopup")
history.find_element_by_xpath('.//span[contains(@class, "history-method") and text()="{}"]'.format(method))
history.find_element_by_xpath('.//span[contains(@class, "history-url") and text()="{}"]'.format(url))
history = context.browser.find_element(By.ID, "HistoryPopup")
history.find_element(By.XPATH, './/span[contains(@class, "history-method") and text()="{}"]'.format(method))
history.find_element(By.XPATH, './/span[contains(@class, "history-url") and text()="{}"]'.format(url))

@then('there are no entries in history')
def step_impl(context):
context.execute_steps(u'''
given I open History dialog
''')
history = context.browser.find_element_by_id("HistoryPopup")
entries = len(history.find_elements_by_xpath('.//li[not(@data-clone-template)]'))
history = context.browser.find_element(By.ID, "HistoryPopup")
entries = len(history.find_elements(By.XPATH, './/li[not(@data-clone-template)]'))
assert entries == 0, "History list is not empty"

@when('I remove the first element in the history list')
def step_impl(context):
context.execute_steps(u'''
given I open History dialog
''')
history = context.browser.find_element_by_id("HistoryPopup")
entries = history.find_elements_by_xpath('.//li[not(@data-clone-template)]')
history = context.browser.find_element(By.ID, "HistoryPopup")
entries = history.find_elements(By.XPATH, './/li[not(@data-clone-template)]')
assert len(entries) > 0, "There are no entries in the history"
item = entries[0]
item.find_elements_by_xpath('.//*[@data-delete-item]')[0].click()
item.find_elements(By.XPATH, './/*[@data-delete-item]')[0].click()
59 changes: 31 additions & 28 deletions tests/steps/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ def step_impl(context):

@given('request method is "{method}"')
def step_impl(context, method):
method_select = context.browser.find_element_by_id('Method')
method_select = context.browser.find_element(By.ID, 'Method')
Select(method_select).select_by_value(method)

@then('request method is "{method}"')
def step_impl(context, method):
select_txt = context.browser.find_element_by_id('Method').get_attribute("value")
select_txt = context.browser.find_element(By.ID, 'Method').get_attribute("value")
assert method == select_txt

@given('url is "{url}"')
def step_impl(context, url):
input_txt = context.browser.find_element_by_id('Url')
input_txt = context.browser.find_element(By.ID, 'Url')
input_txt.clear()
input_txt.send_keys(url)
# Hide history
Expand All @@ -40,12 +40,12 @@ def step_impl(context, url):

@then('url is "{url}"')
def step_impl(context, url):
input_txt = context.browser.find_element_by_id('Url').get_attribute("value")
input_txt = context.browser.find_element(By.ID, 'Url').get_attribute("value")
assert url == input_txt

@step('I click on send')
def step_impl(context):
send_button = context.browser.find_element_by_id('Send')
send_button = context.browser.find_element(By.ID, 'Send')
send_button.click()

@step('I press Ctrl+Enter')
Expand All @@ -54,7 +54,7 @@ def step_impl(context):

@when('I press Enter on the url textbox')
def step_impl(context):
input_txt = context.browser.find_element_by_id('Url')
input_txt = context.browser.find_element(By.ID, 'Url')
input_txt.send_keys(Keys.ENTER)

@step('I wait for request to finish')
Expand Down Expand Up @@ -114,83 +114,86 @@ def step_impl(context):
@then('response contains the following headers')
def step_impl(context):
for row in context.table:
header_name = context.browser.find_element_by_xpath("//*[@id='ResponseHeaders']//span[text()='{}']".format(row['key']))
header_name = context.browser.find_element(By.XPATH, "//*[@id='ResponseHeaders']//span[text()='{}']".format(row['key']))
assert header_name, "Header '{}' not found".format(row['key'])
header_value = context.browser.find_element_by_xpath("//*[@id='ResponseHeaders']//span[text()='{}']".format(row['value']))
header_value = context.browser.find_element(By.XPATH, "//*[@id='ResponseHeaders']//span[text()='{}']".format(row['value']))
assert header_value, "Header value not found"

@then('return code is "{code}"')
def step_impl(context, code):
status = context.browser.find_element_by_id('ResponseStatus')
status = context.browser.find_element(By.ID, 'ResponseStatus')
if not status:
assert False, "Can't find status"
assert code.upper() == status.text.upper(), "Received code [{}], expected [{}]".format(status.text, code)

@then('request size is "{size}"')
def step_impl(context, size):
resp = context.browser.find_element_by_id('ResponseSize')
resp = context.browser.find_element(By.ID, 'ResponseSize')
assert size.upper() == resp.text.upper(), "Received [{}], expected [{}]".format(resp.text, code)

@step('I open "{name}" section')
def step_impl(context, name):
elem = context.browser.find_element_by_xpath("//section/h3[text()='{}']".format(name))
parent = elem.find_elements_by_xpath('..')[0]
elem = context.browser.find_element(By.XPATH, "//section/h3[text()='{}']".format(name))
parent = elem.find_elements(By.XPATH, '..')[0]
if 'closed' in parent.get_attribute('class'):
elem.click()
time.sleep(1) # Wait for section to open

@step('I add Basic Auth header for user "{name}" with pass "{password}"')
def step_impl(context, name, password):
# Open Basic Auth Form
context.browser.find_element_by_xpath("//*[@data-reveal-id='BasicAuthForm']").click()
context.browser.find_element(By.XPATH, "//*[@data-reveal-id='BasicAuthForm']").click()
time.sleep(0.5) # Waiting for modal to open
# Write user
user_txt = context.browser.find_element_by_xpath("//*[@id='BasicAuthForm']//input[@name='user']")
user_txt = context.browser.find_element(By.XPATH, "//*[@id='BasicAuthForm']//input[@name='user']")
user_txt.clear()
user_txt.send_keys(name)
# Write pass
pass_txt = context.browser.find_element_by_xpath("//*[@id='BasicAuthForm']//input[@name='pass']")
pass_txt = context.browser.find_element(By.XPATH, "//*[@id='BasicAuthForm']//input[@name='pass']")
pass_txt.clear()
pass_txt.send_keys(password)
# Save
save_btn = context.browser.find_element_by_xpath("//*[@id='BasicAuthForm']//input[@value='Save']")
save_btn = context.browser.find_element(By.XPATH, "//*[@id='BasicAuthForm']//input[@value='Save']")
save_btn.click()
time.sleep(0.5) # Waiting for modal to close

@step('I add the following headers to the request')
def step_impl(context):
for row in context.table:
context.browser.find_element_by_xpath("//*[@data-clone-item='#HeadersTable']").click()
context.browser.find_element(By.XPATH, "//*[@data-clone-item='#HeadersTable']").click()
time.sleep(0.1)
# Complete header name
name_txt = context.browser.find_element_by_xpath("//*[@id='HeadersTable']/li[last()]/input[1]")
name_txt = context.browser.find_element(By.XPATH, "//*[@id='HeadersTable']/li[last()]/input[1]")
name_txt.clear()
name_txt.send_keys(row['key'])
# Header value
value_txt = context.browser.find_element_by_xpath("//*[@id='HeadersTable']/li[last()]/input[2]")
value_txt = context.browser.find_element(By.XPATH, "//*[@id='HeadersTable']/li[last()]/input[2]")
value_txt.clear()
value_txt.send_keys(row['value'])

@given('a RAW body')
def step_impl(context):
# Open RAW sub-tab
context.browser.find_element_by_xpath('//section[@id="BodySection"]//a[@href="#PanelRaw"]').click()
context.browser.find_element(By.XPATH, '//section[@id="BodySection"]//a[@href="#PanelRaw"]').click()
# Set editor value
output = context.browser.execute_script("return restman.ui.editors.setValue('#RequestContent', atob('{}'));".format(base64.b64encode(context.text)))
script = f"""
return restman.ui.editors.setValue('#RequestContent', atob('{base64.b64encode(context.text.encode("ascii")).decode("ascii")}'));
"""
output = context.browser.execute_script(script)

@given('a FORM body')
def step_impl(context):
# Open FORM sub-tab
context.browser.find_element_by_xpath('//section[@id="BodySection"]//a[@href="#PanelForm"]').click()
context.browser.find_element(By.XPATH, '//section[@id="BodySection"]//a[@href="#PanelForm"]').click()
for row in context.table:
context.browser.find_element_by_xpath("//*[@data-clone-item='#FormData']").click()
context.browser.find_element(By.XPATH, "//*[@data-clone-item='#FormData']").click()
time.sleep(0.1)
# Complete header name
name_txt = context.browser.find_element_by_xpath("//*[@id='FormData']/li[last()]/input[1]")
name_txt = context.browser.find_element(By.XPATH, "//*[@id='FormData']/li[last()]/input[1]")
name_txt.clear()
name_txt.send_keys(row['key'])
# Header value
value_txt = context.browser.find_element_by_xpath("//*[@id='FormData']/li[last()]/input[2]")
value_txt = context.browser.find_element(By.XPATH, "//*[@id='FormData']/li[last()]/input[2]")
value_txt.clear()
value_txt.send_keys(row['value'])

Expand All @@ -199,7 +202,7 @@ def step_impl(context):
context.execute_steps(u'''
given I open "Headers" section
''')
context.browser.find_element_by_xpath('//*[@data-clear-all="#HeadersTable"]').click()
context.browser.find_element(By.XPATH, '//*[@data-clear-all="#HeadersTable"]').click()
time.sleep(0.1)

@then('headers section contains the following headers')
Expand All @@ -225,9 +228,9 @@ def step_impl(context):
context.execute_steps(u'''
given I open "Body" section
''')
context.browser.find_element_by_xpath('//section[@id="BodySection"]//a[@href="#PanelForm"]').click()
context.browser.find_element(By.XPATH, '//section[@id="BodySection"]//a[@href="#PanelForm"]').click()
time.sleep(0.1)
context.browser.find_element_by_xpath('//*[@data-clear-all="#FormData"]').click()
context.browser.find_element(By.XPATH, '//*[@data-clear-all="#FormData"]').click()
time.sleep(0.1)

@given('I clean RAW body')
Expand Down
16 changes: 10 additions & 6 deletions tests/steps/share.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def step_impl(context):
context.execute_steps(u'''
given I open History dialog
''')
history = context.browser.find_element_by_id("HistoryPopup")
entries = history.find_elements_by_xpath('.//li[not(@data-clone-template)]')
history = context.browser.find_element(By.ID, "HistoryPopup")
entries = history.find_elements(By.XPATH, './/li[not(@data-clone-template)]')
assert len(entries) > 0, "There are no entries in the history"
item = entries[0]
item.find_elements_by_xpath('.//*[@data-share-item]')[0].click()
item.find_elements(By.XPATH, './/*[@data-share-item]')[0].click()

@then('the json to share is shown with url "{url}" and contains the following headers')
def step_impl(context, url):
Expand All @@ -41,7 +41,7 @@ def step_impl(context):
given I open History dialog
''')
# Click on import
context.browser.find_element_by_id('ImportHistory').click()
context.browser.find_element(By.ID, 'ImportHistory').click()
WebDriverWait(context.browser, 10).until(
expected_conditions.visibility_of_element_located(
(By.ID, 'ImportRequestForm')))
Expand All @@ -63,9 +63,13 @@ def step_impl(context, url):
}
}
})
context.browser.execute_script("return restman.ui.editors.setValue('#ImportRequestEditor', atob('{}'));".format(base64.b64encode(req)))
# Set editor value
script = f"""
return restman.ui.editors.setValue('#ImportRequestEditor', atob('{base64.b64encode(req.encode("ascii")).decode("ascii")}'));
"""
output = context.browser.execute_script(script)

@step('I click on load import request')
def step_impl(context):
# Import request
context.browser.find_element_by_xpath("//*[@id='ImportRequestForm']//input[@value='Import']").click()
context.browser.find_element(By.XPATH, "//*[@id='ImportRequestForm']//input[@value='Import']").click()