How to use DeviceDescriptors class of PuppeteerSharp.Mobile package

Best Puppeteer-sharp code snippet using PuppeteerSharp.Mobile.DeviceDescriptors

DeviceDescriptors.cs

Source:DeviceDescriptors.cs Github

copy

Full Screen

...3{4 /// <summary>5 /// Device descriptors.6 /// </summary>7 public static class DeviceDescriptors8 {9 private static readonly Dictionary<DeviceDescriptorName, DeviceDescriptor> Devices = new Dictionary<DeviceDescriptorName, DeviceDescriptor>10 {11 [DeviceDescriptorName.BlackberryPlayBook] = new DeviceDescriptor12 {13 Name = "Blackberry PlayBook",14 UserAgent = "Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML like Gecko) Version/7.2.1.0 Safari/536.2+",15 ViewPort = new ViewPortOptions16 {17 Width = 600,18 Height = 1024,19 DeviceScaleFactor = 1,20 IsMobile = true,21 HasTouch = true,...

Full Screen

Full Screen

MatchTask.cs

Source:MatchTask.cs Github

copy

Full Screen

...126 ExecutablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",127 Headless = false128 });129 var page = await browser.NewPageAsync();130 DeviceDescriptor IPhone = DeviceDescriptors.Get(DeviceDescriptorName.IPhone6);131 var dic = new Dictionary<string, string>();132 dic.Add("Referer", _settings.Bet365.Url.MainPage.ToString());133 dic.Add("Accept-Encoding", "gzip, deflate, br");134 dic.Add("Accept-Language", "zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6");135 dic.Add("Connection", "keep-alive");136 await page.EmulateAsync(IPhone);137 await page.SetRequestInterceptionAsync(true);138 await page.SetExtraHttpHeadersAsync(dic);139 page.Request += async (sender, e) =>140 {141 if (e.Request.ResourceType == ResourceType.Image)142 await e.Request.AbortAsync();143 else144 await e.Request.ContinueAsync();...

Full Screen

Full Screen

Program.cs

Source:Program.cs Github

copy

Full Screen

...9namespace PuppeteerSharp.DevicesFetcher10{11 class Program12 {13 const string DEVICES_URL = "https://raw.githubusercontent.com/puppeteer/puppeteer/master/src/common/DeviceDescriptors.ts";14 static readonly string deviceDescriptorsOutput = "../../../../PuppeteerSharp/Mobile/DeviceDescriptors.cs";15 static readonly string deviceDescriptorNameOutput = "../../../../PuppeteerSharp/Mobile/DeviceDescriptorName.cs";16 static async Task Main(string[] args)17 {18 var url = DEVICES_URL;19 if (args.Length > 0)20 {21 url = args[0];22 }23 Console.WriteLine($"GET {url}");24 var text = await HttpGET(url);25 const string DeviceArray = "Device[] = [";26 var startIndex = text.IndexOf(DeviceArray) + DeviceArray.Length;27 var endIndex = text.IndexOf("];", startIndex);28 var length = endIndex - startIndex;29 text = "[" + text.Substring(startIndex, length) + "]";30 Device[] devices;31 try32 {33 devices = JsonConvert.DeserializeObject<Device[]>(text);34 }35 catch (Exception ex)36 {37 Console.WriteLine($"FAILED: error parsing response - {ex.Message}");38 return;39 }40 WriteDeviceDescriptors(devices);41 WriteDeviceDescriptorName(devices);42 }43 static void WriteDeviceDescriptors(IEnumerable<Device> devices)44 {45 var builder = new StringBuilder();46 var begin = @"using System;47using System.Collections.Generic;48using System.Collections.ObjectModel;49namespace PuppeteerSharp.Mobile50{51 /// <summary>52 /// Device descriptors.53 /// </summary>54 public static class DeviceDescriptors55 {56 private static readonly Dictionary<DeviceDescriptorName, DeviceDescriptor> Devices = new Dictionary<DeviceDescriptorName, DeviceDescriptor>57 {58";59 var end = @"60 };61 private static Lazy<IReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor>> _readOnlyDevices =62 new Lazy<IReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor>>(() => new ReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor>(Devices));63 internal static IReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor> ToReadOnly() => _readOnlyDevices.Value;64 /// <summary>65 /// Get the specified device description.66 /// </summary>67 /// <returns>The device descriptor.</returns>68 /// <param name=""name"">Device Name.</param>...

Full Screen

Full Screen

Puppeteer.cs

Source:Puppeteer.cs Github

copy

Full Screen

...85 /// }86 /// ]]>87 /// </code>88 /// </example>89 public static IReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor> Devices => DeviceDescriptors.ToReadOnly();90 }91}...

Full Screen

Full Screen

TestConstants.cs

Source:TestConstants.cs Github

copy

Full Screen

...17 public const string AboutBlank = "about:blank";18 public static readonly string CrossProcessHttpPrefix = "http://127.0.0.1:8907";19 public static readonly string EmptyPage = $"{ServerUrl}/empty.html";20 public static readonly string CrossProcessUrl = ServerIpUrl;21 public static readonly DeviceDescriptor IPhone = DeviceDescriptors.Get(DeviceDescriptorName.IPhone6);22 public static readonly DeviceDescriptor IPhone6Landscape = DeviceDescriptors.Get(DeviceDescriptorName.IPhone6Landscape);23 public static ILoggerFactory LoggerFactory { get; private set; }24 public static readonly string NestedFramesDumpResult = @"http://localhost:<PORT>/frames/nested-frames.html25 http://localhost:<PORT>/frames/two-frames.html26 http://localhost:<PORT>/frames/frame.html27 http://localhost:<PORT>/frames/frame.html28 http://localhost:<PORT>/frames/frame.html";29 public static LaunchOptions DefaultBrowserOptions() => new LaunchOptions30 {31 SlowMo = Convert.ToInt32(Environment.GetEnvironmentVariable("SLOW_MO")),32 Headless = Convert.ToBoolean(Environment.GetEnvironmentVariable("HEADLESS") ?? "true"),33 Args = new[] { "--no-sandbox" },34 Timeout = 0,35 KeepAliveInterval = 120,36 LogProcess = true...

Full Screen

Full Screen

PuppeteerEngine.cs

Source:PuppeteerEngine.cs Github

copy

Full Screen

...21 }22 public async Task<Page> newPage()23 {24 var page = await _browser.NewPageAsync();25 DeviceDescriptor IPhone = DeviceDescriptors.Get(DeviceDescriptorName.IPhone6);26 var dic = new Dictionary<string, string>();27 dic.Add("Referer", _settings.Bet365.Url.MainPage.ToString());28 dic.Add("Accept-Encoding", "gzip, deflate, br");29 dic.Add("Accept-Language", "zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6");30 dic.Add("Connection", "keep-alive");31 await page.EmulateAsync(IPhone);32 await page.SetRequestInterceptionAsync(true);33 await page.SetExtraHttpHeadersAsync(dic);34 page.Request += async (sender, e) =>35 {36 if (e.Request.ResourceType == ResourceType.Image)37 await e.Request.AbortAsync();38 else39 await e.Request.ContinueAsync();...

Full Screen

Full Screen

DeviceDescriptors

Using AI Code Generation

copy

Full Screen

1using PuppeteerSharp.Mobile;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 var deviceDescriptors = new DeviceDescriptors();12 var device = deviceDescriptors.Get("iPhone 6");13 Console.WriteLine(device.UserAgent);14 Console.WriteLine(device.Viewport.Width);15 Console.WriteLine(device.Viewport.Height);16 Console.WriteLine(device.Viewport.DeviceScaleFactor);17 Console.WriteLine(device.Viewport.IsMobile);18 Console.WriteLine(device.Viewport.HasTouch);

Full Screen

Full Screen

DeviceDescriptors

Using AI Code Generation

copy

Full Screen

1var device = PuppeteerSharp.Mobile.DeviceDescriptors.IPhoneX;2var options = new LaunchOptions { Headless = true, DefaultViewport = null };3var browser = await Puppeteer.LaunchAsync(options);4var page = await browser.NewPageAsync();5await page.ScreenshotAsync("google.png");6await browser.CloseAsync();

Full Screen

Full Screen

DeviceDescriptors

Using AI Code Generation

copy

Full Screen

1using PuppeteerSharp.Mobile;2using System.Threading.Tasks;3{4 {5 {6 UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1",7 {8 }9 };10 }11}12using PuppeteerSharp;13using PuppeteerSharp.Mobile;14using System.Threading.Tasks;15{16 {17 public string Name { get; set; }18 public string UserAgent { get; set; }19 public ViewPortOptions Viewport { get; set; }20 }21}22using PuppeteerSharp;23using System.Threading.Tasks;24{25 {26 public int Width { get; set; }27 public int Height { get; set; }28 public int DeviceScaleFactor { get; set; }29 public bool IsMobile { get; set; }30 public bool HasTouch { get; set; }31 public bool IsLandscape { get; set; }32 }33}34using PuppeteerSharp;35using System.Threading.Tasks;36{37 {38 public static Task<Browser> LaunchAsync(LaunchOptions options = null)39 {40 return new BrowserFetcher(options).DownloadAndLaunchAsync(options);41 }42 }43}44using PuppeteerSharp;45using System.Threading.Tasks;46{47 {48 public BrowserFetcher(LaunchOptions options = null)49 {50 }51 public Task<Browser> DownloadAndLaunchAsync(Launch

Full Screen

Full Screen

DeviceDescriptors

Using AI Code Generation

copy

Full Screen

1var deviceDescriptors = new DeviceDescriptors();2var device = deviceDescriptors.GetDevice("iPhone 6");3{4 Args = device.GetArgs()5};6var browser = await Puppeteer.LaunchAsync(options);7var page = await browser.NewPageAsync();8await page.ScreenshotAsync("google.png");9{10 UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1",11 {12 }13};14{15 Args = device.GetArgs()16};17var browser = await Puppeteer.LaunchAsync(options);18var page = await browser.NewPageAsync();19await page.ScreenshotAsync("google.png");20{21};22{23 Args = mobileEmulation.GetArgs()24};25var browser = await Puppeteer.LaunchAsync(options);26var page = await browser.NewPageAsync();27await page.ScreenshotAsync("google.png");28{29};30var browser = await Puppeteer.LaunchAsync(options);31var page = await browser.NewPageAsync();32await page.EmulateAsync(new DeviceDescriptor33{34 UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1

Full Screen

Full Screen

DeviceDescriptors

Using AI Code Generation

copy

Full Screen

1var deviceDescriptors = new DeviceDescriptors();2var device = deviceDescriptors.GetDevice("iPhone X");3var options = new LaunchOptions { Headless = false, Args = new string[] { "--start-maximized" } };4var browser = await Puppeteer.LaunchAsync(options);5var page = await browser.NewPageAsync();6await page.SetViewportAsync(device.ViewPort);7await page.ScreenshotAsync("google.png");8var deviceDescriptors = new DeviceDescriptors();9var device = deviceDescriptors.GetDevice("iPhone X");10var options = new LaunchOptions { Headless = false, Args = new string[] { "--start-maximized" } };11var browser = await Puppeteer.LaunchAsync(options);12var page = await browser.NewPageAsync();13await page.SetViewportAsync(device.ViewPort);14await page.ScreenshotAsync("google.png");15var deviceDescriptors = new DeviceDescriptors();16var device = deviceDescriptors.GetDevice("iPhone X");17var options = new LaunchOptions { Headless = false, Args = new string[] { "--start-maximized" } };18var browser = await Puppeteer.LaunchAsync(options);19var page = await browser.NewPageAsync();20await page.SetViewportAsync(device.ViewPort);21await page.ScreenshotAsync("google.png");22var deviceDescriptors = new DeviceDescriptors();23var device = deviceDescriptors.GetDevice("iPhone X");24var options = new LaunchOptions { Headless = false, Args = new string[] { "--start-maximized" } };25var browser = await Puppeteer.LaunchAsync(options);26var page = await browser.NewPageAsync();27await page.SetViewportAsync(device.ViewPort);28await page.ScreenshotAsync("google.png");29var deviceDescriptors = new DeviceDescriptors();30var device = deviceDescriptors.GetDevice("iPhone X");31var options = new LaunchOptions { Headless = false, Args = new string[] { "--

Full Screen

Full Screen

DeviceDescriptors

Using AI Code Generation

copy

Full Screen

1using PuppeteerSharp.Mobile;2using PuppeteerSharp.Mobile;3var deviceDescriptors = new DeviceDescriptors();4var deviceDescriptor = new DeviceDescriptor();5var deviceDescriptor = new DeviceDescriptor();6using PuppeteerSharp.Mobile;7using PuppeteerSharp.Mobile;8var deviceDescriptor = new DeviceDescriptor();9var deviceDescriptor = new DeviceDescriptor();10using PuppeteerSharp.Mobile;11using PuppeteerSharp.Mobile;12var deviceDescriptor = new DeviceDescriptor();13var deviceDescriptor = new DeviceDescriptor();14using PuppeteerSharp.Mobile;15using PuppeteerSharp.Mobile;16var deviceDescriptor = new DeviceDescriptor();17var deviceDescriptor = new DeviceDescriptor();18using PuppeteerSharp.Mobile;19using PuppeteerSharp.Mobile;20var deviceDescriptor = new DeviceDescriptor();21var deviceDescriptor = new DeviceDescriptor();22using PuppeteerSharp.Mobile;23using PuppeteerSharp.Mobile;

Full Screen

Full Screen

DeviceDescriptors

Using AI Code Generation

copy

Full Screen

1using PuppeteerSharp.Mobile;2{3 {4 static void Main(string[] args)5 {6 var device = DeviceDescriptors.IPhone6();7 {8 };9 var browser = Puppeteer.LaunchAsync(options).Result;10 var page = browser.NewPageAsync().Result;11 browser.CloseAsync().Wait();12 }13 }14}15using PuppeteerSharp.Mobile;16{17 {18 static void Main(string[] args)19 {20 var device = DeviceDescriptors.IPhone6();21 {22 };23 var browser = Puppeteer.LaunchAsync(options).Result;24 var page = browser.NewPageAsync().Result;25 browser.CloseAsync().Wait();26 }27 }28}29using PuppeteerSharp.Mobile;30{31 {32 static void Main(string[] args)33 {34 var device = DeviceDescriptors.IPhone6();35 {36 };37 var browser = Puppeteer.LaunchAsync(options).Result;38 var page = browser.NewPageAsync().Result;39 browser.CloseAsync().Wait();40 }41 }42}43using PuppeteerSharp.Mobile;44{45 {46 static void Main(string[] args)47 {48 var device = DeviceDescriptors.IPhone6();49 {

Full Screen

Full Screen

DeviceDescriptors

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 {9 };10 var deviceDescriptor = PuppeteerSharp.Mobile.DeviceDescriptors.Get("Nexus 5X");11 options.UserAgent = deviceDescriptor.UserAgent;12 options.DefaultViewport = deviceDescriptor.ViewPort;13 using (var browser = await Puppeteer.LaunchAsync(options))14 {15 var page = await browser.NewPageAsync();16 await page.ScreenshotAsync("nexus5x.png");17 }18 }19 }20}21using System;22using System.Threading.Tasks;23using PuppeteerSharp;24{25 {26 static async Task Main(string[] args)27 {28 {29 };30 var deviceDescriptor = PuppeteerSharp.Mobile.DeviceDescriptors.Get("Galaxy S5");31 options.UserAgent = deviceDescriptor.UserAgent;32 options.DefaultViewport = deviceDescriptor.ViewPort;33 using (var browser = await Puppeteer.LaunchAsync(options))34 {35 var page = await browser.NewPageAsync();36 await page.ScreenshotAsync("galaxys5.png");37 }38 }39 }40}41using System;42using System.Threading.Tasks;

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in DeviceDescriptors

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful