vendredi 13 septembre 2019

How to have a global variable running the generate random keyword while assigning in robot framework

I have automated filling out an online form using selenium driver, I then converted all my hard coded input to variables, now i am trying to generate random strings for a couple of the variables that must change to make the form submission work each time. I have the field 'surname' and i want to input a random string and assign to a variable. Later in the code I then want to be able to compare this variable in the database against what was input into the form. My issue is I cannot seem to assign the variable using the keyword whilst keeping it global. I have tried numerous things, and read and researched a lot but still cannot get it and its probably something small im missing.

I have the following files which i have / can pull in as resources so that the variable is able to be recognized in each file.

1. Tests.robot - This is the runtime file and actual file i will have my test cases
2. AboutPage.robot - This file contains all variables and keywords to fill out each field on the first page of the form
3. FormKeywords - This is just a file which contains keywords for each page of the form so it can call the keywords in about page in a logical order
4. common.robot - this has my keywords for common functions such as logging into the DB and bringing back data 

I have tried creating keywords and test cases to return the variable. Tried to use set global variable keyword within a keyword, tried to run the keyword while assigning it as a variable.

My Test case in the Tests.robot file is:
Test name
   [Documentation]  test is to check documents are attached in db
   Fill in about you page
   click document menu button
   Upload documents
   click continue button
   Fill in other information
   click continue button
   Click submit application button
   Log into database

The 'Fill in about you page' has the following keyword:
    Input surname

The 'Input surname' keyword is on the following page with the current code:
    ***Keywords***
    Input surname  ${RANDOM_SURNAME}
    input text  ${surname_id}  ${RANDOM_SURNAME}

Currently i have also tried to put the variable code in here as another keyword so that it can be passed to the input surname keyword. 
    Generate random surname string
    ${RANDOM_SURNAME} =  Generate Random String  8  [LOWER]
    set global variable  ${RANDOM_SURNAME}
    [Return]

    -------------------
Due to another answer and similar question on here I also tried:
    Generate random surname string
        ${RANDOM_SURNAME} =  Generate Random String  8  [LOWER]
        set global variable  ${RANDOM_SURNAME}
        [Return]
        Generate surname  ${RANDOM_SURNAME}

    Generate surname
      [Arguments]  ${RANDOM_SURNAME}
      log to console  \nattempting input surname  ${RANDOM_SURNAME}
      set global variable  ${RANDOM_SURNAME}

Initially in the variables section I have tried several variations of the following - but my issue is i cannot call the 'generate random string' keyword in the variables section. When i move the code into the keywords section and set as global variable it is still not recognized in the other files. The variable is only recognizable when in the variables section but then it wont call the keyword:

    ***Variables***
    1. ${RANDOM_SURNAME}=  Generate random string  8  [LOWER]
    2. Set Global variable ${RANDOM_SURNAME}=  Generate random string  8     [LOWER]

 As a testcase:
    ***Test Cases*** 
    3. ${RANDOM_SURNAME}=  Generate random string  8  [LOWER]
       set global variable  ${RANDOM_SURNAME}

Depending on the code - I can run it and as it doesnt pick up the keyword it inserts 'Generate random surname' as the surname into the form Or atm I am getting the 'keyword name cannot be empty' this is using the keyword method but it is obv not generating or passing the string to the final keyword.

I am expecting a random string to be assigned to the variable which is global and can be used and referred to throughout the other page objects enter code hereand keywords.




Aucun commentaire:

Enregistrer un commentaire