Create multiple windows with persistent context using playwright - playwright

I'm trying to launch multiple windows that are using the same user data dir.
When launching using browserType.launchPersistentContext(userDataDir[, options])] and then using browserContext.newPage() multiple times:
import playwright from 'playwright'
const browserContext = await playwright.chromium.launchPersistentContext('/tmp/profile', { headless: false })
await (await browserContext.newPage()).goto('https://example.com')
await (await browserContext.newPage()).goto('https://example.com')
await (await browserContext.newPage()).goto('https://example.com')
it will launch one window and then open one tab per page.
Unfortunately, browserContext.browser() specifically doesn't work for persistent contexts:
Returns the browser instance of the context. If it was launched as a persistent context null gets returned.
so I cannot create multiple contexts.
How would I go with making it open multiple windows when using persistent contexts?

I have debugged the communication between the Playwright package v1.24 and the Firefox browser. It seems to open multiple windows, all of them sharing a common browser context. As far as I can see, the only limitation is that you cannot open the pages in the same window.

Related

Run Appium tests against APP or IPA files?

I'm facing an issue in which I can't tap on some elements because they belong to a view/window that is on another layer of where the Appium driver operates. This would be solved if I could somehow change the focus to this new layer, like we do in Webdriver with the window handles methods.
I think I can workaround over this issue by executing my tests on the simulator (app file) instead of real device (ipa file) which led me to think. Is it a wrong approach to try to test on real device with ipa file?
I don't think so but that's what came to my mind after this situation.
What type of view it is ? In appium we have context concept.
When you are trying to interact with native component of any app in ios and android the it is known is native context and when elements are in any webview then it is webview context. You can get available context anytime using following code:
Set<String> contexts = driver.getContextHandles()
For example if you want to switch to webview then you can use following code:
Set<String> contexts = driver.getContextHandles();
for (String context : contexts) {
if (context.contains("WEBVIEW")) {
driver.context("WEBVIEW");
}
}

Visual Studio Mac Streaming BasicHttpBinding not working

I have a cross platform app that runs on Windows and Mac. It is using WCF on .NET 4.5.2. In the BasicHttpBinding configuration in the settings file I am setting the transferMode="Streaming". We are downloading large files using this service.
On Windows everything works fine. The WCF method call returns right away and then when I read from the Stream member of the MessageContract object the file is streamed as excepted.
When I run the same app in Visual Studio for Mac I have 2 problems. The first problem is that the transfer mode in the binding is Buffered instead of Streamed.
I fix that by changing it in code after creating the channel. Here is the code I use to do it. Maybe this is the problem:
private IDataService CreateClient()
{
Channel = new ChannelFactory<IDataService>(BindingId);
var binding = Channel.Endpoint.Binding as BasicHttpBinding;
binding.TransferMode = TransferMode.Streamed;
Channel = new ChannelFactory<IDataService> (binding, Channel.Endpoint.Address);
var client = Channel.CreateChannel();
return client;
}
Notice how I read the binding, change the transfer mode and then create a new channel using the new binding. This seemed to be the best way to get the same settings from the settings file, but switch the transfer mode.
When the download method call is made I am able to see in the debugger where the transfer mode on the binding is Streamed, where before it was Buffered.
The problem I have at this point is that even though the transfer mode is Streamed, the download WCF method call doesn't return until the whole file is downloaded. It is acting like it is still in Buffered mode.
Any ideas how to fix this?
It looks like the streaming setting doesn't work in the Xamarin implementation of .net 4.5.2 that we are using. Not sure if it works in later versions or not.
I ended up adding a REST api just for downloading large files...

Accessing the DOM between two renderers in Electron

Is it possible to do this in Electron:
I want to duplicate a video to a 2nd screen.
This is easyly done, by invoking the following 50 times/second:
canvas_context_2nd_screen.drawImage(video_1st_screen,0,0,width_canvas_2nd,height_canvas_2nd);
but in electron i have to communicate via IPC...
any ideas? is it possible in nw.js?
It is supported in NW.js. As DOM windows are in the same renderer process by default, and the Node.js context is shared between them:
http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/
This can be changed to be separate though.

Weird DartEditor behavior / bug?

I'm working on a little website using dart.
I have one project for the server, and another for the client app (see picture below)
In the server app I serve the client app from the client project like this
runServer() {
var staticHandler = createStaticHandler(r"C:\Users\Lukasz\dart\linkShepherdClient\web\", defaultDocument: 'linkShepherd.html',serveFilesOutsidePath: true);
var handler = new Cascade()
.add(staticHandler)
.add(routes.handler)
.handler;
io.serve(handler, InternetAddress.LOOPBACK_IP_V4, 8080).then((server) {
print('Listening on port 8080');
}).catchError((error) => print(error));
}
Everything worked fine. But now the changes I do in the client project stopped affecting the site served by the server (a site still loads, just an older version, with slightly different styling, but most importantly also an older .dart script file). When I run the client directly from it's project everything is up to date.
Opening and closing the editor does not help.
Is the dart editor actually creating some sort of cache?
The cache might be from dart:io. You should probably launch a pub serve instance and redirect to this during development anyway. This way any transformers (Angular, Polymer, ...) are applied as well.
When deployed the server should serve the build output of the client.

opening-local-html-file-with-android-browser in android 3.x

with android 2.x i could use the solution
browserIntent.setClassName("com.android.browser", "com.android.browser.BrowserActivity")
resolved in the post:
opening local html file with Android Browser
but with android 3.2 i have this error:
Unable to find explicit activity class
(com.android.browser/com.android.browser.BrowserActivity);
have you declared this activity in your AndroidManifest.xml?
I think that the class com.android.browser.BrowserActivity doesn't exist in Android 3.x
Any solution?
Not a satisfying solution, but in a demo application I alternatively used the following code:
String url = "content://com.android.htmlfileprovider/sdcard/mydir/myfile.html";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "text/html");
startActivity(intent);
Usually at least one of the two works.
https://github.com/nicolas-raoul/OxygenGuide-Android/blob/master/src/org/github/OxygenGuide/MainActivity.java#L69
intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity")
Will open whatever app has the packagename "com.android.browser". The issue with using this is that over various versions of android and various manufacturers, the default browser changes. For example Nexus devices tend to come pre-installed with the chrome app, which has a different package name.
Unable to find explicit activity class
(com.android.browser/com.android.browser.BrowserActivity);
have you declared this activity in your AndroidManifest.xml?
The error you have copied explains that there is no application with that package name browserIntent.setClassName() is used to open a specific app explicitly which means it shouldn't provide a prompt asking which browser you would like to use.
If this is what you want to avoid (pop up), then you can check what browsers are on the device and possibly suggest downloading it before making links clickable.
you also could use the code from the other suggestion.
String url = "content://com.android.htmlfileprovider/sdcard/mydir/myfile.html";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "text/html");
startActivity(intent);
This specifies that you want to open an activity that can handle the "text/html" type data. By viewing it. This would provide you with a list of applications (different installed browsers) for you to select.
Uri uri = Uri.parse(url);
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setDataAndType(uri, "text/html");
browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
startActivity(browserIntent);

Resources