How to find current url for mobile testing in appium - appium

I am doing automation testing using appium selenium .Can anybody help me with finding current url for mobile driver . Tried with driver.getCurrentUrl() . it's not working

You need to check the context of the app :
If context is native app , you cant get url of any screen.
If App context is having WEBVIEW you will get URL
How to check context :
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextNames);
}
You can switch to WEBVIEW using following code :
if (contextName.contains("WEBVIEW")) {
driver.context("WEBVIEW");
driver.getCurrentUrl()
}

Related

find and share a downloaded video on Flutter ios without going through picker?

I have a Flutter app that can view mp4 files from a URL. (Using a video controller playing directly from the URL.) I want the user to be able to share them if they wish. As best I can tell the file has to actually exist on the device so I have broken down the steps for now into download file, invoke share.
I'm using this guide: https://retroportalstudio.medium.com/saving-files-to-application-folder-and-gallery-in-flutter-e9be2ebee92a
I need to work on ios and android. The problem is that on ios neither the filename I get from the dio downloader nor the ImageGallerySaver seem to "work" when passed to the system ShareSheet.
I'm using the flutter extensions dio, share_plus, cross_file, image_gallery_saver as I've seen recommended in various places.
File saveFile = File(directory.path + "/$fileName");
developer.log("starting download...");
await dio.download(url, saveFile.path,
onReceiveProgress: (value1, value2) {
developer.log("got progress " + value1.toString());
setState(() {
downloadProgress = value1 / value2;
});
});
_permaFile = saveFile.path;
if (Platform.isIOS) {
var galleryResult = await ImageGallerySaver.saveFile(saveFile.path,
isReturnPathOfIOS: true);
developer.log("gallery save result = " + galleryResult.toString());
_permaFile = galleryResult['filePath'];
}
After getting a directory we use dio to download the file, do some log chirping, and then save the name to an object member called _permaFile.
Then the share button triggers:
void _shareAction() async {
final box = context.findRenderObject() as RenderBox?;
final files = <XFile>[];
if (_permaFile == null) {
return;
}
developer.log("sharing file: " + _permaFile.toString());
files.add(XFile(_permaFile!));
await Share.shareXFiles(files,
text: "Event",
// subject: "Subject for Event",
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size);
}
This works on android device... after I download I hit share, and I can share the video to a third-party app like WhatsApp.
On ios the ShareSheet is invoked but when I share I only get the text "Event", not the video file that goes along with it.
Note that I have tried both results... setting the _permaFile to be what comes back from ImageGallerySaver but also just using what the dio downloader gives back.
Note also that the ImageGallerySaver seems to work: the video really does land and is there in the ios video lib. If I go into the Photos app I can share from there to WhatsApp and have the video get sent.
In each case I get errors like this:
[ShareSheet] error fetching item for URL:file:/var/mobile/Media/DCIM/100APPLE/IMG_0021.MP4 -- file:/// : (null)
[ShareSheet] error fetching file provider domain for URL:file:/var/mobile/Media/DCIM/100APPLE/IMG_0021.MP4 -- file:/// : (null)
[ShareSheet] error loading metadata for
documentURL:file:/var/mobile/Media/DCIM/100APPLE/IMG_0021.MP4 --
file:/// error:Error Domain=NSFileProviderInternalErrorDomain Code=0
"No valid file provider found from URL
file:/var/mobile/Media/DCIM/100APPLE/IMG_0021.MP4 -- file:///."
UserInfo={NSLocalizedDescription=No valid file provider found from URL
file:/var/mobile/Media/DCIM/100APPLE/IMG_0021.MP4 -- file:///.}
In order to test this further I built the share_plus demo app:
https://github.com/fluttercommunity/plus_plugins/tree/main/packages/share_plus/share_plus
I modified it to share videos to see what was different. The share plus example (sp_example) works for sharing videos that have been selected by the picker.
For this reason I think the problem is something I'm missing about ios video filenames/formats and possibly a built-in conversion step that happens.
Here are what the filenames look like that I see in my app:
dio download result:
file:///var/mobile/Containers/Data/Application/223BF2B9-DDF0-490E-932F-09D5F03B98B3/Library/Caches/test.mp4
ImageGallerySaver result:
file:///var/mobile/Media/DCIM/100APPLE/IMG_0019.MP4
This is what video filenames look like when they are picked and shared in sp_example:
/private/var/mobile/Containers/Data/Application/E5CB4D7C-6CDF-4AA2-8134-C4322ED7C886/tmp/trim.E6633D68-44E3-4853-A29E-A71AC95A0913.MOV
Note that it has been converted to MOV extension and the user gets trim step right in the picker that results in trim in the name.
For my purposes I don't want to go through the picker, the user is on the screen showing the video and they shouldnt have to repick, so where do I get the post-conversion ios filename that references what I just saved?

Automate launching Safari from a iOS mobile app using appium

I am doing some automation with Appium on a iOS mobile app.
I need to:
open the app
do some tasks
open safari
I looked around how to do it but I've been reading that it's impossible due to a limitation in apple's framework, it doesn't allow you to sent commands to more than one app per session.
Does anyone know a way around this? Or if what I read is just not 100% true.
it doesn't allow you to sent commands to more than one app per session
Thats true, but you can run 2 sessions in a single test:
create instance of appium driver with app-based capabilities
do what you need in the app
quit driver
create instance of appium driver with browser-based capabilities
do what you need in the safari
quit driver
In a quick way it may look like:
#Test
public void testBothAppAndSafari() throws MalformedURLException {
URL appiumServerUrl = new URL("<your appium server host>");
DesiredCapabilities appCaps = new DesiredCapabilities();
// put required native app capabilities in appCaps
DesiredCapabilities safariCaps = new DesiredCapabilities();
// put required safari capabilities in safariCaps
IOSDriver driver = new IOSDriver(appiumServerUrl, appCaps);
driver.findElement(<locator for element in native app>).click();
// do whatever you want with mobile app
driver.quit();
driver = new IOSDriver(appiumServerUrl, safariCaps);
driver.findElement(<locator for element in web>).click();
// do whatever you want in safari
driver.quit();
}
You can use following approach,
Created two setup one for app and other for safari.
First launch application and perform task
clear first session
Created again new Appium object for safari ( call second setup )
Perform browser activity
Close safari appium session
You also can follow my approach without quit driver.
Go terminate application. (I've used javascript to run terminateApp cause native method not work for me.)
Find Safari on Home screen and then click on it
Use drive.get to open website as you expected.
In there you can change to WEBVIEW_*** to inspect web element.
Back to native context by NATIVE_APP keyword
Sample code:
System.out.println("Run application");
Map<String, Object> params = new HashMap<>();
params.put("bundleId", "com.example");
boolean terminalApp = (boolean) driver.executeScript("mobile: terminateApp", params);
System.out.println("terminateApp: " + terminateApp);
driver.findElementById("Safari").click();
Set<String> contextNames = appDriver.getContextHandles();
// Change context to WEBVIEW_***
appDriver.context(String.valueOf(contextNames.toArray()[1]));
driver.get("https://www.google.com.vn");
Thread.sleep(20000);
// Do something.
// ...
// If you want to communicate with NATIVE context just change to NATIVE_APP.
appDriver.context("NATIVE_APP");
you can activate system apps via driver.activateApp(BUNDLE_ID);
there is no need to kill the app driver and start browser driver to access browser, just switch between apps.
safari
driver.activateApp("com.apple.mobilesafari");
Here is how I resolved the issue:
driver2.activateApp("com.apple.mobilesafari");
Thread.sleep(5000);
boolean openSafariTab =
driver2.findElements(By.xpath("//XCUIElementTypeButton[#name=\"AddTabButton\"]")).size() > 0;
if (openSafariTab) {
driver2.findElement(By.xpath("//XCUIElementTypeButton[#name=\"AddTabButton\"]")).click();
} else { }
Thread.sleep(3000);
driver2.findElement(By.xpath("//XCUIElementTypeTextField[#name=\"TabBarItemTitle\"]")).click();
Thread.sleep(3000);
driver2.findElement(By.xpath("//XCUIElementTypeOther[#name=\"CapsuleViewController" +
"\"]/XCUIElementTypeOther[3]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]")).sendKeys("https://www.golfbpm.com");
Thread.sleep(3000);
driver2.findElement(By.xpath("//XCUIElementTypeButton[#name=\"Go\"]")).click();

How to get WebView URL in W10 Mobile (UWP) (Xamarin forms)

I'm developing an application for W10 Mobile (UWP) in Xamarin forms and I have implemented a WebView and I tried to get the URL of this but it is more complicated than I thought at first, I tried to get it through the source property, but not is possible, I would appreciate a help.
You could create an event handler to the navigation completed event.
With that you can check the URL
example:
WebView browser = new WebView();
browser.Navigated += OnNavigatedHandler;
public void OnNavigatedHandler (object sender, WebNavigatedEventArgs args){
Console.WriteLine ("Navigated to: " + args.Url);
}
I'm having trouble getting the URL of the browser in real time, the way you indicate I enter an infinite loop, I have a binding in my WebView on the SourceProperty in the view model called URL, when there is a change in the URL property I detect it thanks to PropertyChanged, the problem is that the event navigated only runs when updating the value of the URL property which causes the infinite loop to load the WebView infinitely. Is there any other way to get the URL?
I have uploaded in Pastebin the classes of the test project I am using:
View: pastebin.com/msyu9dJF
ViewModel: pastebin.com/LaCfC31c
BaseViewModel: pastebin.com/i6GCFbbe

about blackberry development

I started in blackberry development.
Currently, I try to develop App with:
Blackberry Widget API (Javascript + CSS) and Eclipse (JAVA)
1/
When I try with Blackberry Widget API, I try to load a webservice in .NET, I try to run this in simulator 8520 curve... and the connect to the webservice not works, I use the config.xml to set the domains but nothing happends, later I test in 9800 simulator and works fine... but I have some fear because this app is for run in any device :(
2/
When I try with Eclipse and kSOAP2 Library,
This is my code:
String WSD_URL = "http://service.com/service.asmx";
String WSD_NAMESPACE = "http://service.com/GetInfo";
String WSD_ACTION = "http://service.com/GetInfo/fGetInfo";
SoapObject soap = new SoapObject(WSD_NAMESPACE, "fGetInfo");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.bodyOut = soap;
envelope.encodingStyle = SoapEnvelope.XSD;
HttpTransport ht = new HttpTransport(WSD_URL);
try {
ht.call(WSD_ACTION, envelope);
} catch (Exception e){
}
When I launch the app in simulator... nothing happend, few minutos after I see a error in the white screen with message "controlled access exception" :(
I have doubt here because I dont know how to solve this and if this app run in any devive.
In eclipse I see JRE 6.0
To access dot net webservice, instead of Ksoap method, try this one.. http://whatpaulhaslearnt.wordpress.com/2011/04/19/consuming-a-net-web-service-from-a-blackberry-native-application-using-the-java-me-platform-sdk-3/ .. this is the best way of accessing dot net webservice..

blackberry java webservice error

i didnt get the output of the code.
HttpConnection httpConn;
httpConn = (HttpConnection)Connector.open("http://mydomainname.getsample.php?getData=mydata");
httpConn.setRequestMethod(HttpConnection.GET);
int iResponseCode = httpConn.getResponseCode();
System.out.print(iResponseCode);
what is the error?. how i get the output ?
iam using blackberry simulator. on pc, the url retriving the data.
if you are using eclipse
right click on the project->run as ->run configurations->simulator
check the option for launch mds with simulator.

Resources