Adding new tests to the new methods.

anticaptcha
Pedro de Oliveira Guedes 2022-01-06 11:14:52 -03:00
parent 1855094014
commit babfb1c1cd
2 changed files with 74 additions and 11 deletions

View File

@ -1,34 +1,39 @@
Feature: The Chrome API client Feature: The Chrome API client
# ======================== Chrome.start() ========================
Scenario: Using the Chrome.start method Scenario: Using the Chrome.start method
Given the Chrome client Given the Chrome client
When the start method is called When the start method is called
Then Google Chrome must open Then Google Chrome must open
# ======================== Chrome.start_headless() ========================
Scenario: Using the Chrome.start_headless method Scenario: Using the Chrome.start_headless method
Given the Chrome client Given the Chrome client
When the start_headless method is called When the start_headless method is called
Then Google Chrome must open headless Then Google Chrome must open headless
# ======================== Chrome.stop() ========================
Scenario: Using the Chrome.stop method Scenario: Using the Chrome.stop method
Given the Chrome client Given the Chrome client
And a Chrome instance And a Chrome instance
When the stop method is called upon it When the stop method is called upon it
Then this Google Chrome instance must close Then this Google Chrome instance must close
# ======================== Chrome.new() ========================
Scenario: Using the Chrome.new method Scenario: Using the Chrome.new method
Given the Chrome client Given the Chrome client
And a Chrome instance And a Chrome instance
When the new method is called When the new method is called
Then a new Google Chrome tab with the url given must open in the instance Then a new Google Chrome tab with the url given must open in the instance
# ======================== Chrome.close() ========================
Scenario: Using the Chrome.close method Scenario: Using the Chrome.close method
Given the Chrome client Given the Chrome client
And a Chrome instance And a Chrome instance
And the id of a new Google Chrome tab opened And the id of a new Google Chrome tab opened
When the close method is called upon the tab id When the close method is called upon the tab id
Then the tab must close Then the tab must close
# ======================== Chrome.eval() ========================
Scenario: Using the Chrome.eval method for arithmetics Scenario: Using the Chrome.eval method for arithmetics
Given the Chrome client Given the Chrome client
And a Chrome instance And a Chrome instance
@ -41,4 +46,24 @@ Feature: The Chrome API client
And a Chrome instance And a Chrome instance
And the id of a new Google Chrome tab opened in google.com And the id of a new Google Chrome tab opened in google.com
When the eval method is called upon the tab id with a JS command When the eval method is called upon the tab id with a JS command
Then this command must give back the element requested as a value Then this command must give back the element requested as a value
# ======================== Chrome.wait() ========================
Scenario: Using the Chrome.wait method
Given the Chrome client
And a Chrome instance
And the id of a new Google Chrome tab opened in google.com
When the wait method is called upon the tab id with a JS command
Then this method must return the string 'ok'
# ======================== Chrome.send() ========================
# This method cannot be tested, given it's return cannot be predicted.
# Therefore, there will be no testes for this method, at least for now.
# ======================== Chrome.open_tabs() ========================
Scenario: Using the Chrome.open_tabs method
Given the Chrome client
And a Chrome instance
And at least one Google Chrome tab is opened
When the open_tabs method is called
Then it must return a list of dictionaries containing the tabs data

View File

@ -71,22 +71,60 @@ def step_impl(context):
# ========================== Chrome.eval () ========================== # ========================== Chrome.eval () ==========================
@when ("the eval method is called upon the tab id with a arithmetic command") @when ("the eval method is called upon the tab id with a arithmetic command")
def step_impl(context): def step_impl(context):
context.eval_value = context.client.eval(context.tab_id1, "2+2") context.eval_value_arit = context.client.eval(context.tab_id1, "2+2")
@then ("this command must give back the result as a value") @then ("this command must give back the result as a value")
def step_impl(context): def step_impl(context):
assert context.eval_value == 4, "The command did not worked as expected." assert context.eval_value_arit == 4, "The command did not worked as expected."
context.client.stop() context.client.stop()
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@given ("the id of a new Google Chrome tab opened in google.com") @given ("the id of a new Google Chrome tab opened in google.com")
def setp_impl(context): def setp_impl(context):
context.tab_id = context.client.new() context.tab_id = context.client.new()
@when ("the eval method is called upon the tab id with a JS command") @when ("the eval method is called upon the tab id with a JS command")
def step_impl(context): def step_impl(context):
context.eval_value = context.client.eval(context.tab_id, "document.getElementById('SIvCob').textContent") _ = context.client.wait(context.tab_id, "document.getElementById('SIvCob') != undefined", 5)
context.eval_value_js = context.client.eval(context.tab_id, "document.getElementById('SIvCob').textContent")
@then ("this command must give back the element requested as a value") @then ("this command must give back the element requested as a value")
def step_impl(context): def step_impl(context):
assert context.eval_value == 'Disponibilizado pelo Google em: English ', "The command did not worked as expected." assert context.eval_value_js == 'Disponibilizado pelo Google em: English ', "The command did not worked as expected."
context.client.stop()
# ========================== Chrome.wait () ==========================
@when("the wait method is called upon the tab id with a JS command")
def step_impl(context):
context.wait_return = context.client.wait(context.tab_id, "document.getElementById('SIvCob') != undefined", 5)
@then("this method must return the string 'ok'")
def step_impl(context):
assert context.wait_return == "ok", "The command did not worked as expected."
context.client.stop()
# ========================== Chrome.send () ==========================
"""
This method cannot be tested, given it's return cannot be predicted.
Therefore, there will be no tests for this method, at least for now.
"""
# ========================== Chrome.open_tabs () ==========================
@given("at least one Google Chrome tab is opened")
def step_impl(context):
context.tab_id1 = context.client.new()
context.tab_id2 = context.client.new("https://www.youtube.com")
@when("the open_tabs method is called")
def step_impl(context):
context.open_tabs_return = context.client.open_tabs()
@then("it must return a list of dictionaries containing the tabs data")
def step_impl(context):
assert context.open_tabs_return[1]["id"] == context.tab_id1, f"""
----------
Google id: {context.tab_id1}
Primeiro obj id: {context.open_tabs_return[1]['id']}
{context.open_tabs_return[1]['id'] == context.tab_id1}
----------
"""
context.client.stop() context.client.stop()