hi iam using andriod driver to test my product in mobile.i want to
take snapshot of tests running in real device .is there any solutions?
I believe AndroidDriver extends RemoteWebDriver. RemoteWebDriver does not implement TakeScreenshot interface. Therefore you need to use augmenter like below. I never tried this on Android device but am thinking this should technically work.
driver = new AndroidDriver();
driver = (new Augmenter()).augment(driver);
File temp = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(temp, new File("C:\\my\\picture\\test.png"));
Edit#1
I checked that AndroidDriver implementes TakeScreenshot interface here. That means you don't need to augment the driver.
Related
Is there a way to check the connect ability of a BLE device in Xamarin.Forms (I'm using Plugin.BLE)? I need a method (similar to isConnactable) that will check the connect ability of each element from the ObservableCollection. I'm developing an Android application, so cross-platform is not necessary.
Sample illustration in code:
ObservableCollection<IDevice> DevicesList = new ObservableCollection<IDevice>();
ObservableCollection<IDevice> IsConnactableDevicesList = new ObservableCollection<IDevice>();
DevicesList = new ObservableCollection<IDevice>();
IsConnactableDevicesList = IfDeviceConnactable(DevicesList);
Do you mean the connectable property sent in the advertising packet? (i.e. https://developer.android.com/reference/android/bluetooth/le/ScanResult#isConnectable()). It seems your chosen library does not expose that info. You can skip the plugin and call the native Android framework directly to get this working, since you don't need cross platform compatibility anyway.
You can also modify the plugin to make it expose this info.
I'm hitting this error:
java.lang.SecurityException: adb clearing user data is forbidden.'; Code: '1'
while running the below mentioned code on appium server in android 8.1.0 (oreo) but the same code is running fine in android 5.1 (lollipop). USB debugging is already on in mobile. Anyone having any idea why I'm hitting this error?`
package appium;
#BeforeTest
public void setcapbilities() throws Exception
{
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("deviceName","Vipul");
cap.setCapability(CapabilityType.VERSION,"8.1");
cap.setCapability("platformName","Android");
cap.setCapability("appPackage","com.android.calculator2");
cap.setCapability("appActivity","com.android.calculator2.Calculator");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap);
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
}
#Test
public void firstt()
{
driver.findElement(By.xpath("//android.widget.Button")).click();
driver.findElement(By.xpath("7")).click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
#AfterTest
public void kill()
{
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
driver.quit();
}
There few pointers which you can try to solve the issue you're facing.
First, use latest stable Appium server and Java client available.
Second, use AndroidDriver <MobileElement> instead of RemoteWebDriver. Since, AndroidDriver extends RemoteWebDriver via AppiumDriver, it must have overiden the quit method functionality.
Third, you don't need to call implicit wait everywhere. You must call it once in your set up method.
Forth, update your Android SDK and tools to latest.
It is not neccessary that if a something works in andorid v5 , then it should also work on android v8
Reason
To make the devices more secure , latest android versions are imposing restrictions on some already working APIs.
e.g. You can enable airplane mode using Appium API in mobile devices till Android V6, from Android V7 onwards this API has been blocked.
Solution
looking at your code, it seems ,the session should get created successfully , the only thing u need to take care is how to make your test successfull. May be you need to change your Xpath as per the UI for Android V8.
did you try checking this Xpath in APPIUM Desktop ?
https://automationlab0000.wordpress.com/2018/12/31/appium-desktop-for-locating-elements/
I am a beginner in automation testing. I am trying to write common test project for my android and ios app. Both the apps on ios and android have almost same UI and flow. I want to know how can I instantiate Appium driver for based on the platform.
As of now, I am thinking to have a boolean variable isAndroid which I would have to manually change in the code before running the tests.Based on isAndroid I instantiate AppiumDriver to AndroidDriver or IOSDriver and elements will be located as per #AndroidFindby or #IOSFindBy
When I start Appium from the terminal, I mention the parameter platformName, is there a way to fetch that information in my code so that I do not have to manually change isAndroid variable and exactly same test code runs on both platforms.
Are you able to try one platform, catch the exception and then try the other?
try:
driver = webdriver.Remote('http://localhost:4723/wd/hub', ios_caps)
run_iOS_tests(driver)
except selenium.common.exceptions.WebDriverException:
driver = webdriver.Remote('http://localhost:4723/wd/hub', android_caps)
run_android_tests(driver)
Otherwise you'll need to use some external method to see what devices are connected (android, ios).
I'm trying to write some test scripts which involves uploading a file via Chrome. I'm using Selenium's RemoteWebDriver in order to test the web application using Chrome on a Samsung Note 10 device.
I've managed to write the script up to the point of clicking on the file upload button which in turn bring up the file upload control asking me which type of file I'd like to upload. However since this is not a web control I can't interact with it using RemoteWebDriver. I tried to create a new instance of AppiumDriver but since an instance of RemoteWebDriver already exists I'm unable to create a new instance of AppiumDriver.
Is there anyway I could go about this issue? I tried to cast RemoteWebDriver as a AppiumDriver (despite feeling that it wouldn't work) but it wasn't possible.
You can start the test with AndroidDriver initialization instead of RemoteWebDriver.
The reason to this is its implementation:
AndroidDriver extends AppiumDriver extends DefaultGenericMobileDriver extends RemoteWebDriver
So, you will have something like:
WebDriver driver = new AndroidDriver(new URL(YOUR_REMOTE_MACHINE_HUB_URL), capabilities);
Now, you can use AppiumDriver methods. You can upload file with in-built technique that WebDriver provide for this.
The main idea behind it is to directly send the absolute path to the file to an element which you would usually click at to get the modal window - that is <input type='file' /> element.
WebElement fileInput = driver.findElement(By.xpath("//input[#type='file']"));
fileInput.sendKeys("C:/file_to_upload.jpg");
Since I'm working in a platform which works with many apps (rather than a single target app), I find the selection of a target app inefficient for my needs. I wondered if I could do something to avoid it.
I'd like to run freely, sending UI commands to iOS and Android real devices, including installing an app from another app (like Play Store, Apple Store, Test Flight, etc.)
Thanks for the help,
David.
The rule is: 1 Webdriver instance per application.
You can run Appium's server with no --app argument by making sure auto-launch is set to false, and not setting bundleId or app.
Then, in your client/test framework, you use several webdrivers, configured to use different desired capabilities, to tie it all together under a single test case/suite.
The solution:
You may have a test suite that sets desired_capabilities to launch the Safari app, then you install the app, then you quit the webdriver.
Then you change the desired_capabilities to point to the bundle_id of the new app, launch another webdriver instance, do your tests, quit the webdriver..
Then you change the desired_capabilities to point to (etc., etc.)
driver = webdriver.new(url, desired_capabilities)
// do some stuff
driver.quit()
desired_capabilities['app'] = 'company.app.com'
driver = webdriver.new(url, desired_capabilities)
// do some stuff
driver.quit()
desired_capabilities['app'] = '/path/to/application.app'
driver = webdriver.new(url, desired_capabilities)
// do some stuff
driver.quit()