From 7baf408c05e3cc6014bd85b5fb338d904afa1585 Mon Sep 17 00:00:00 2001 From: Pedro de Oliveira Guedes Date: Thu, 6 Jan 2022 08:20:44 -0300 Subject: [PATCH] Updating the eval tests. --- api/chrome/features/chrome.feature | 13 ++++++++++--- api/chrome/features/steps/steps.py | 23 ++++++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/api/chrome/features/chrome.feature b/api/chrome/features/chrome.feature index 566f534..2fd0771 100644 --- a/api/chrome/features/chrome.feature +++ b/api/chrome/features/chrome.feature @@ -29,9 +29,16 @@ Feature: The Chrome API client When the close method is called upon the tab id Then the tab must close - Scenario: Using the Chrome.eval method + Scenario: Using the Chrome.eval method for arithmetics Given the Chrome client And a Chrome instance And the id of a new Google Chrome tab opened - When the eval method is called upon the tab id with a command - Then this command must give back a value \ No newline at end of file + When the eval method is called upon the tab id with a arithmetic command + Then this command must give back the result as a value + + Scenario: Using the Chrome.eval method for JavaScript commands + Given the Chrome client + And a Chrome instance + 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 + Then this command must give back the element requested as a value \ No newline at end of file diff --git a/api/chrome/features/steps/steps.py b/api/chrome/features/steps/steps.py index 1377218..edc0084 100644 --- a/api/chrome/features/steps/steps.py +++ b/api/chrome/features/steps/steps.py @@ -42,7 +42,7 @@ def step_impl (context): # ========================== Chrome.new () ========================== -@when("the new method is called") +@when ("the new method is called") def step_impl(context): context.tab_id = context.client.new("https://www.youtube.com") @@ -62,18 +62,31 @@ def step_impl(context): def step_impl(context): context.close_return = context.client.close(context.tab_id1) -@then("the tab must close") +@then ("the tab must close") def step_impl(context): assert context.close_return == "", "The tab did not closed correctly." context.client.stop() # ========================== Chrome.eval () ========================== -@when("the eval method is called upon the tab id with a command") +@when ("the eval method is called upon the tab id with a arithmetic command") def step_impl(context): context.eval_value = context.client.eval(context.tab_id1, "2+2") -@then("this command must give back a value") +@then ("this command must give back the result as a value") def step_impl(context): - assert context.eval_value != None, "The command did not worked as expected." + assert context.eval_value == 4, "The command did not worked as expected." + context.client.stop() + +@given ("the id of a new Google Chrome tab opened in google.com") +def setp_impl(context): + context.tab_id = context.client.new() + +@when ("the eval method is called upon the tab id with a JS command") +def step_impl(context): + context.eval_value = context.client.eval(context.tab_id, "document.getElementById('SIvCob').textContent") + +@then ("this command must give back the element requested as a value") +def step_impl(context): + assert context.eval_value == 'Disponibilizado pelo Google em: English ', "The command did not worked as expected." context.client.stop() \ No newline at end of file