mirror of
https://github.com/microsoft/playwright-java.git
synced 2025-09-08 21:01:00 +00:00
fix: allow to build options from DeviceDescriptor (#151)
This commit is contained in:
parent
ec86901e97
commit
ef6adb8123
@ -1102,6 +1102,10 @@ class NestedClass extends TypeDefinition {
|
||||
}
|
||||
} else {
|
||||
writeBuilderMethods(output, bodyOffset);
|
||||
if ("Browser.newContext.options".equals(jsonPath) ||
|
||||
"Browser.newPage.options".equals(jsonPath)) {
|
||||
writeDeviceDescriptorBuilder(output, bodyOffset);
|
||||
}
|
||||
}
|
||||
output.add(offset + "}");
|
||||
}
|
||||
@ -1133,6 +1137,16 @@ class NestedClass extends TypeDefinition {
|
||||
output.add(bodyOffset + "}");
|
||||
}
|
||||
|
||||
private void writeDeviceDescriptorBuilder(List<String> output, String bodyOffset) {
|
||||
output.add(bodyOffset + "public " + name + " withDevice(DeviceDescriptor device) {");
|
||||
output.add(bodyOffset + " withViewport(device.viewport().width(), device.viewport().height());");
|
||||
output.add(bodyOffset + " withUserAgent(device.userAgent());");
|
||||
output.add(bodyOffset + " withDeviceScaleFactor(device.deviceScaleFactor());");
|
||||
output.add(bodyOffset + " withIsMobile(device.isMobile());");
|
||||
output.add(bodyOffset + " withHasTouch(device.hasTouch());");
|
||||
output.add(bodyOffset + " return this;");
|
||||
output.add(bodyOffset + "}");
|
||||
}
|
||||
}
|
||||
|
||||
class Enum extends TypeDefinition {
|
||||
|
@ -326,6 +326,14 @@ public interface Browser {
|
||||
this.storageStatePath = storageStatePath;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withDevice(DeviceDescriptor device) {
|
||||
withViewport(device.viewport().width(), device.viewport().height());
|
||||
withUserAgent(device.userAgent());
|
||||
withDeviceScaleFactor(device.deviceScaleFactor());
|
||||
withIsMobile(device.isMobile());
|
||||
withHasTouch(device.hasTouch());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class NewPageOptions {
|
||||
public class RecordHar {
|
||||
@ -600,6 +608,14 @@ public interface Browser {
|
||||
this.storageStatePath = storageStatePath;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withDevice(DeviceDescriptor device) {
|
||||
withViewport(device.viewport().width(), device.viewport().height());
|
||||
withUserAgent(device.userAgent());
|
||||
withDeviceScaleFactor(device.deviceScaleFactor());
|
||||
withIsMobile(device.isMobile());
|
||||
withHasTouch(device.hasTouch());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* In case this browser is obtained using browserType.launch([options]), closes the browser and all of its pages (if any were
|
||||
|
Loading…
x
Reference in New Issue
Block a user