使用selenium ide记录测试用例以进行反应应用,但是能够从selenium-ide上传文件不起作用。 React-dropzone包用于文件上传。
尝试使用命令“类型”和“发送密钥”,但没有工作。
selenium-ide:3.6.0 chrome:74.0.3729.108
尝试使用Firefox但收到错误消息“目前只支持Chrome上传文件”
Command: type
Target: css=input[type=file]
Value: c:\fakepath\test.png
Error: {"code":-32000,"message":"Not allowed"}
Command: send keys
Target: css=input[type=file]
Value: c:\fakepath\test.png
Error: Element is not currently interactable and may not be manipulatedElement is not currently interactable and may not be manipulated
selenium ide能够上传文件并通过测试用例。
尝试使用Firefox但收到错误消息“目前只支持Chrome上传文件”
此问题与React或SIDE无关。所有支持从扩展程序(例如iMacros,SIDE,...)上传文件的浏览器扩展程序都通过Chrome调试API执行此操作。 Firefox没有这样的扩展API =>无法实现文件上传自动化。
解决方案:使用Kantu Selenium IDE。它使用外部的本机助手应用程序(称为“XModules”)来克服这些限制,因此也支持automating file uploads in Firefox。
测试Chrome的宏:
{
"Name": "1upload",
"CreationDate": "2019-5-2",
"Commands": [
{
"Command": "open",
"Target": "https://cgi-lib.berkeley.edu/ex/fup.html",
"Value": ""
},
{
"Command": "XClick",
"Target": "name=upfile",
"Value": ""
},
{
"Command": "XType",
"Target": "C:\\1tmp\\1test.txt",
"Value": ""
},
{
"Command": "XType",
"Target": "${KEY_ENTER}",
"Value": ""
},
{
"Command": "clickAndWait",
"Target": "xpath=/html/body/form/input[3]",
"Value": ""
}
]
}
测试Firefox的宏
在这里,XType | ${KEY_ENTER}
不起作用(我不知道为什么)。因此,我使用desktop automation在“打开”按钮上用xclick替换它。使用的图像是:
{
"Name": "1upload-firefox",
"CreationDate": "2019-5-2",
"Commands": [
{
"Command": "open",
"Target": "https://cgi-lib.berkeley.edu/ex/fup.html",
"Value": ""
},
{
"Command": "XClick",
"Target": "name=upfile",
"Value": ""
},
{
"Command": "XType",
"Target": "C:\\1tmp\\1test.txt",
"Value": ""
},
{
"Command": "comment",
"Target": "XType // ${KEY_ENTER}",
"Value": ""
},
{
"Command": "XDesktopAutomation",
"Target": "true",
"Value": ""
},
{
"Command": "XClick",
"Target": "[email protected]",
"Value": ""
},
{
"Command": "clickAndWait",
"Target": "xpath=/html/body/form/input[3]",
"Value": ""
}
]
}