Interacting with UI Form via a test label instead of a label

Certified Senior Developer
This is with regards to Performance Testing. We are using Locust as the tool for PT.
We have certain Interface components where label is not defined as per design. 
When writing PT scripts Locust for Appian provides functions to interact with a "testLabel" if label is not available.
I want to interact with a dropdown using a test label. But the appian interface designer does not provide an attribute called "testLabel" for dropdown component.
Reference:

  Discussion posts and replies are publicly visible

Parents
  •   could you please suggest a code how to use testLable if label is not available on click download excel file link? as I am new to Appian-locust.

  • 0
    Certified Senior Developer
    in reply to mohammads3449

    Hi  

    Usually we don't included download link as part of perf test. I am guessing you want to measure the download time for the file.

    I don't see any functions provided in "appian for lucust" for this. So I guess you may need to,

    1. Get the _documentDownloadLink from json response of your the last ui form interact call.

    2. Form the download link url using "/suite/rest/a/content/latest/{opaqueContentId}/o" replace opaqueContentId with _documentDownloadLink

    3. Call self.client.get using the above url.

  • Thanks for update  

    I tried to follow above steps you suggested. But I am get below error:

    Error report
    # occurrences Error
    ------------------|-------------------------------------------------------------------------------------------------------------------------------------------1 GET /suite/rest/a/content/latest/_documentDownloadLink/o: HTTPError('500 Server Error: 500 for url: /suite/rest/a/content/latest/_documentDownloadLink/o')
    ------------------|-------------------------------------------------------------------------------------------------------------------------------------------

    On hitting manually below URL :

    xxxxx.appiancloud.com/.../o

    getting below error on browser:

    {"error":"APNX-1-0000-000","message":"An error was encountered while processing your request. "}
  • 0
    Certified Senior Developer
    in reply to mohammads3449

    Hi, Hope you have replaced with the actual encoded string from last response.

    For example this is a section from response json. 

    "link": {
        "_documentDownloadLink": "ioB7vr6GjFvUNxPq2Miwv1qGKHukxgjgKuFwb6p5zZv_2wQwAlSDT3Igbo",
        "_cId": "f12c63bb69315fb33e3137d47088dfdd",
        "document": {
          "id": 771239,
          "#t": "CollaborationDocument"
        },
        "label": "",
        "version": -1,
        "metricKey": "",
        "#t": "DocumentDownloadLink"
      }

    So the document url will be,

    /suite/rest/a/content/latest/ioB7vr6GjFvUNxPq2Miwv1qGKHukxgjgKuFwb6p5zZv_2wQwAlSDT3Igbo/o

  • Hi, Yes same I did.

    Below is the section from response json.

    link":{
    "_documentDownloadLink":"ioBRM6r2ZR-dSBC6M8A0YS40UJXHFJgjNtYJ5Ng6MK1HKkLRJarnhLJCk",
    "_cId":"321f7b1bea2d292db37226961ae7b5f6",
    "testLabel":"Download Activity Task Loader",
    "document": {
    "id":223327,
    "#t":"CollaborationDocument"
    },
    "label":"",
    "version":-1,
    "metricKey":"",
    "#t":"DocumentDownloadLink"}

    Also how to correlate above _documentDownlaodLink value in Appian Locust sail Ui Form?

  • 0
    Certified Senior Developer
    in reply to mohammads3449

    Able to call the download link successfully

    "GET /suite/rest/a/content/latest/ioBRBhHZ1P0RUrscUV0M2LUTUPJN2o1Gn3nC7TwumKibZU5Y6k1G4ZL7BQ/o HTTP/11" 200

    Locust task looks like this

        @task
        def download_document(self):
            headers = self.interact.setup_sail_headers()
            
            response = self.client.get(
                f"/suite/rest/a/content/latest/{self.opaqueContentId}/o",
                allow_redirects=True,
                name=f"08 - Download Document - {self.task_name}",
                headers=headers
            )

    Like I mentioned, save the self.opaqueContentId from previous response (here I have used a custom function)

    self.opaqueContentId = find_unique_key(json_response, "_documentDownloadLink")

    You will need to traverse the json using standard python and correlate using a label field.

  • Thank you   for you support and quick response.

    Actually below is my script:

    @task
    def validateATL(self):
    response = self.client.get('/suite/sites/maestro')
    if response.ok:
    alt_UiForm = self.appian.visitor.visit_site('Maestro', 'home')
    alt_UiForm.click_card_layout_by_index(4)
    alt_UiForm.select_dropdown_item('Saved Searches', 'PT1')
    alt_UiForm.click_button('SEARCH FOR DATA PREVIEW')
    alt_UiForm.click_button('Export tO Excel')


    Here I am getting confused how to get the json response from '
    Export tO Excel' button of SailUIForm on run time. as I am getting response from first step:

    response = self.client.get('/suite/sites/maestro')

    In the same way how did I get from
    alt_UiForm.click_button('Export tO Excel')

    how ever I get the json response from it and save that file in response folder only for debugging purpose
    and that too will be memory issue in the long run to save these json files.


    Regards,

  •  

    I tried with below code but not able to get the value of _documentDownloadLink variable:

    corrResp = alt_UiForm.click_button('Export tO Excel')
    jsonResponse = corrResp.get_latest_state()
    print(jsonResponse)
    try:
    opaqueContentId = re.search(r"_documentDownloadLink\':\'(.+?)\',", jsonResponse.text)
    self.opaqueContentId = opaqueContentId.group(1)
    print(self.opaqueContentId)
    except AttributeError:
    self.opaqueContentId = ""

    please suggest is it the right way or not.
  • 0
    Certified Senior Developer
    in reply to mohammads3449

    Yes thats correct. Either use regex search like you have done here, or parse the json and traverse json nodes.

    Maybe try to debug line by line if you are stuck.

Reply Children
  • Thanks for reply. Here I did it as shown below:

    response = alt_UiForm.click_button('Export tO Excel')
    corresp = response.get_latest_state()
    ddl = str(corresp).split("'link': {'_documentDownloadLink':")[-1]
    documentDownloadLink = str(ddl).split(",")[0]
    opaqueContentId = re.sub("[' ']","",documentDownloadLink)
    self.client.get(f"/suite/rest/a/content/latest/{opaqueContentId}/o")

    But no downloaded file found in download folder.
  • How can I click on 

    self.client.get(f"/suite/rest/a/content/latest/{opaqueContentId}/o")

    in order to download the file?
  • 0
    Certified Senior Developer
    in reply to mohammads3449

    Hi, I already mentioned the answer above for your use case.

    I think you are confused about some concepts.

    When you click on a download link from the browser, it is html tag with the href attribute which has the location of the file. It is nothing but a http GET url like /suite/rest/a/content/latest/{opaqueContentId}/o . You can verify this by performing inspect on the web page. This URL returns the file.

    In performance test you are only calling web APIs. So when you are using locust of appian click method in _uiform class, this method has the logic to form the request body and call the api to perform the action. Same thing happens via the browser as well but you are just mimicking the api calls using locust.

    So the self.client.get is itself is performing the download. There is no other "click" that you need to do.

  • Thanks for reply. I understand that but I am not able to find the downloaded file any where in my system especially in Download folder. 

  • 0
    Certified Senior Developer
    in reply to mohammads3449

    If you want to see the file you need to save the response from self.client.get and then write the contents to a file. Can refer to this post from locust - https://github.com/locustio/locust/issues/774

    But it defeats the purpose of perf test. Since locust already tracks request/response metrics. For this case it will already show the time taken for download and the size in bytes for the content downloaded.

  • Thank you Jithesh for quick response. you mean to say it is not necessary that file will be downloaded physically in my local drive. 

  • Hi Jithesh,

    When I execute the script with 1 user the upload file works good but I execute the script with 2 or more users it throughs below error:

    2 File "C:\Users\mohammad.war\PycharmProjects\AppianLocust\.venv\Lib\site-packages\locust\user\task.py", line 347, in run self.execute_next_task() File "C:\Users\mohammad.war\PycharmProjects\AppianLocust\.venv\Lib\site-packages\locust\user\task.py", line 372, in execute_next_task self.execute_task(self._task_queue.pop(0)) File "C:\Users\mohammad.war\PycharmProjects\AppianLocust\.venv\Lib\site-packages\locust\user\task.py", line 384, in execute_task task(self) File "C:\Users\mohammad.war\PycharmProjects\AppianLocust\Maestro\ValidateData.py", line 32, in ValidateATL alt_UiForm.upload_document_to_upload_field('Upload Activity Task Loader',testData['filePath']) File "C:\Users\mohammad.war\PycharmProjects\AppianLocust\.venv\Lib\site-packages\appian_locust\uiform\uiform.py", line 1135, in upload_document_to_upload_field component = find_component_by_attribute_in_dict( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\mohammad.war\PycharmProjects\AppianLocust\.venv\Lib\site-packages\appian_locust\utilities\helper.py", line 209, in find_component_by_attribute_in_dict component = find_component_by_type_and_attribute_and_index_in_dict(component_tree, attribute=attribute, value=value, raise_error=raise_error) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\mohammad.war\PycharmProjects\AppianLocust\.venv\Lib\site-packages\appian_locust\utilities\helper.py", line 351, in find_component_by_type_and_attribute_and_index_in_dict raise ComponentNotFoundException(f"No components with {attribute} '{value}' found on page") No components with label 'Upload Activity Task Loader' found on page