简体   繁体   中英

Is there a cross-platform solution to interacting with node OS when using selenium grid?

I wrote some selenium tests that were run and passed locally. I wrote them for Windows/Chrome. At one point, my app opens up a local file explorer to upload a file. To interact with this I used AutoIt, which solved my problem. However, now I am moving my tests to grid (through lambdatest) and I am testing on both Windows and Mac. AutoIt only works on Windows, and out of the box it only works locally. I know some solutions have been offered to use AutoIt remotely, but this doesn't help me with Mac OS.

Is there a general solution for how to approach interacting with a remote machine during a selenium test?

Any help is appreciated. I'm not sure how to approach this.

EDIT: After looking around at a lot of solutions to this, the below is what I have been trying but the test times out because it cannot find the file input. I know there must be some way to do this. People testing apps on MacOS can't use AutoIT, so what is the solution?

        # upload photo
        photo_upload_element = wait1.until(
            EC.visibility_of_element_located((By.CLASS_NAME, 'reply-field__button--cam'))).click()
        time.sleep(2)
        file_input = self.driver1.find_element_by_css_selector("input[type='file']")
        time.sleep(2)
        file_input.send_keys(DIR_PATH + r"\path\to\local\photo.jpg")
        time.sleep(2)
        file_input.send_keys(Keys.RETURN)
        time.sleep(2)
        wait1.until(
            EC.visibility_of_element_located((By.CLASS_NAME, 'buttons-grid__button'))).click()
        time.sleep(2)

Here is the html on the page for the input:

<template>
  <input
    class="fileselect"
    v-on:change="handleFileSelect"
    ref="fileinput"
    id="cam"
    type="file"
    accept="image/*"
    :capture="camera"
    data-testid="fileselect"
  />
</template>

Can anyone suggest a solution? 在此处输入图像描述

Please make sure you use the file detector is implemented when running tests on the grid that should take care of this kind of issue.

You can refer to the below link for more information on the file detector. File Detector in Remoter Driver implementation

I think we don't have to use AutoIT in this case, as the input type is file ideally send_keys method should take care of browsing the file.

I think you are trying to manage the browse file issue. If so, you can use pyautogui :

from pyautogui import typewrite

typewrite('file.txt')

typewrite(['enter'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM