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

NOV-244340: expression for selecting in an array for a context storage #388

Conversation

robertomier
Copy link
Contributor

So far....

Expressions starting with CONTEXT let us select elements saved in context or context.storage like

[CONTEXT:a.b.c] returns the 'c' property of the 'b' property of the 'a' element in the context

recently, the index in arrays was added, so that

[CONTEXT:a.1.b] returns the 'b' property of the element with index 1 in the 'a' array

Now...
let's go a bit deeper and let's have a mechanism of selecting elements in an array of dictionaries by searching for an specific key, like this:

having this next structure saved in the context

   {
        "the_array": [
            {
                "id": "first-element",
                "text": "The value of the first element"
            },
            {
                "id": "second-element",
                "text": "The value of the second element"
            }
        ]
    }

we are now able to select like [CONTEXT:the_array.id=first-element.text] and the 'The value of the first element' will be returned

you can also use single or double quotes for the selection expression (id='first-element', "id"="first-element", etc..)

for idx, item in enumerate(the_list):
if key in item and item[key] == value:
return the_list[idx]
return None
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this function.

Copy link
Contributor Author

@robertomier robertomier May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sr codeclimate, puedo quitar algún que otro return en esta función, si le parece, y reemplazarlo con if elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif if elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif if elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif

@robertomier
Copy link
Contributor Author

Code Climate has analyzed commit 06d761e and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2
View more on Code Climate.

Sr codeclimate, puedo meter la función que indica como compleja con if elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif elif ... (que además puede llegar a evaluar por duplicado isinstance(value,list), que es mucho mejor, oiga)
image

Copy link

codeclimate bot commented May 23, 2024

Code Climate has analyzed commit 3ff199a and detected 0 issues on this pull request.

View more on Code Climate.

@rgonalo rgonalo merged commit 9c3eefa into Telefonica:master May 29, 2024
14 checks passed
jruizg23 added a commit that referenced this pull request Jul 15, 2024
* NOV-244340: expression for selecting in an array for a context storage (#388)

* chore: base code for selecting in an array using expresions like a.[key='value'].b

* fix: previous unitary tests with the new code

* test: add positive unitary tests for the new feature

* test: add negative unitary tests

* doc: updated methods docstring

* doc: updated changelog

* fix: flake8 format for unitary testing

* fix: flake8 format for dataset module

* chore: adapt code to codeclimate bot stupidity

* test: add unitary test for invalid list structure

* fix: upgrade Faker version to 25.9 (#394)

* fix: upgrade Faker version to 25.9

* fix Firefox unittests

* bug(QAWTO-212): fix result for action before the feature error with background (#397)

* bug(QAWTO-212): fix action before the feature with background output with error

* fix(QAWTO-212): fix flake8 linter messages

* fix(QAWTO-212): move behave import to selected function

* docs(QAWTO-212): update changelog

* feat: add initial integration of playwright (#387)

* feat: add initial integration of playwright

* avoid error in after_scenario

* feat: reuse toolium driver and pageobjects for playwright tests (#389)

* chore: include playwright module on setup (#391)

* chore: include playwright module on setup

* feat: playwright enable headless config (#392)

* feat: stop playwright when driver is closed (#393)

* playwright start by browser

* avoid duplications for ConfigDriver instance

* fix lint

---------

Co-authored-by: robertomier <[email protected]>
Co-authored-by: Rubén González Alonso <[email protected]>
Co-authored-by: Ricardo García Fernández <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants