How to upload attachments in browser tests using Appium?

风格不统一 提交于 2019-12-25 15:59:27

问题


I am trying to automate a test case in Chrome where I would like to upload an attachment to an email. I use desiredCaps['browserName'] = 'Chrome'. While clicking attachments in email, it opens the Documents in the phone, but I am unable to detect the elements in the Documents screen.


回答1:


Try this.If you are using ruby

This basically goes into the directory called screenshots and finds the second picture or the document that is visible inside the directory

find_element(id: "screenshots").find_element(class: "android.widget.ImageView[2]").click
end

This captures the first document/picture visible in the gallery

find_element(id: "").find_element(class: "android.widget.ImageView").click

You can modify it as per your requirement




回答2:


You shoud change context to from Chromium to 'NATIVE_APP' appium doc about it (http://appium.io/docs/en/writing-running-appium/web/hybrid/) and use Touch Actions for choose you file




回答3:


In Java, you can use the below code to switch context.

Set<String> contextNames = driver.getContextHandles(); 
for (final String contextName : contextNames) { 
if (contextName.contains("NATIVE")) { 
driver.context(contextName); 
System.out.println("Switched to Native Context"); 
} 
}

in Python you can try something like this

contextNames = driver.contexts
for aContext in contextNames
if "NATIVE" in aContext:
driver.switch_to.context(aContext)


来源:https://stackoverflow.com/questions/44180506/how-to-upload-attachments-in-browser-tests-using-appium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!