Skip to content

Commit

Permalink
2.1
Browse files Browse the repository at this point in the history
PlaywrightWindow:
- Added more methods for returning the html and its elements
- Added getAllHeadersAsJson() method
- Added methods for filling forms
- Added methods for retrieving request/response data
- Added methods for keyboard press/hold and typing text
- Added methods for screenshots and setting the screen/viewport size
- Added js code executing method with returning its result
- Added methods for checking/unchecking checkboxes and radio buttons
  • Loading branch information
Osiris-Team committed Oct 15, 2021
1 parent d9531ed commit 3221a3a
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.osiris.headlessbrowser</groupId>
<artifactId>Headless-Browser</artifactId>
<version>2.0</version>
<version>2.1</version>
<repositories>
<repository>
<id>jitpack</id>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/osiris/headlessbrowser/HBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.osiris.headlessbrowser.exceptions.NodeJsCodeException;
import com.osiris.headlessbrowser.windows.HWindow;
import com.osiris.headlessbrowser.windows.PlaywrightWindow;
import com.osiris.headlessbrowser.windows.PuppeteerWindow;
import com.osiris.headlessbrowser.windows.WindowBuilder;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class GraalWindow implements HWindow {
private String javaScriptCode;

/**
* <p style="color: red;">Note that this is not the recommended way of creating a NodeWindow object.</p>
* <p style="color: red;">Note that this is not the recommended way of creating the window object.</p>
* Use the {@link WindowBuilder} instead. The {@link HBrowser} has a shortcut method for creating custom windows: {@link HBrowser#openCustomWindow()}.
*/
public GraalWindow(HBrowser parentBrowser, boolean enableJavaScript, Map<String, String> customHeaders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class LightWindow implements HWindow {
private String javaScriptCode;

/**
* <p style="color: red;">Note that this is not the recommended way of creating a NodeWindow object.</p>
* <p style="color: red;">Note that this is not the recommended way of creating the window object.</p>
* Use the {@link WindowBuilder} instead. The {@link HBrowser} has a shortcut method for creating custom windows: {@link HBrowser#openCustomWindow()}.
*/
public LightWindow(HBrowser parentBrowser, boolean enableJavaScript, Map<String, String> customHeaders,
Expand Down
258 changes: 243 additions & 15 deletions src/main/java/com/osiris/headlessbrowser/windows/PlaywrightWindow.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class PuppeteerWindow implements HWindow {
String url;

/**
* <p style="color: red;">Note that this is not the recommended way of creating a NodeWindow object.</p>
* <p style="color: red;">Note that this is not the recommended way of creating the window object.</p>
* Use the {@link WindowBuilder} instead. The {@link HBrowser} has a shortcut method for creating custom windows: {@link HBrowser#openCustomWindow()}.
*/
public PuppeteerWindow(HBrowser parentBrowser, boolean enableJavaScript, OutputStream debugOutput, int jsTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public static void main(String[] args) {
.build()) {
context.getBindings("js").putMember("javaObj", new MyClass());
boolean valid = context.eval("js",
" javaObj.id == 42" +
" && javaObj.text == '42'" +
" && javaObj.arr[1] == 42" +
" && javaObj.ret42() == 42")
" javaObj.id == 42" +
" && javaObj.text == '42'" +
" && javaObj.arr[1] == 42" +
" && javaObj.ret42() == 42")
.asBoolean();
context.eval("js", "javaObj.print('HELLO!!!');");
assert valid == true;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/osiris/headlessbrowser/Playground.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void testPlaywright() {
try {
hWindow.load("https://spigotmc.org"); // spigotmc.org
Thread.sleep(15000); // So see result
System.out.println(hWindow.getDocument().toString());
System.out.println(hWindow.getOuterHtml().toString());
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import com.osiris.headlessbrowser.HBrowser;
import com.osiris.headlessbrowser.exceptions.NodeJsCodeException;
import org.jsoup.nodes.Attribute;
import org.junit.jupiter.api.Test;

import java.io.File;

import static org.junit.jupiter.api.Assertions.*;

class PlaywrightWindowTest {

/**
Expand All @@ -17,19 +14,22 @@ class PlaywrightWindowTest {
@Test
void fullTest() throws Exception {
HBrowser hBrowser = new HBrowser();
try(PlaywrightWindow window = hBrowser.openCustomWindow().debugOutputStream(System.out).headless(false).buildPlaywrightWindow()){
window.load(new File(System.getProperty("user.dir")+"/test.html"));
try (PlaywrightWindow window = hBrowser.openCustomWindow().debugOutputStream(System.out).headless(false).buildPlaywrightWindow()) {
window.load(new File(System.getProperty("user.dir") + "/test.html"));
formFillingTest(window);
window.load("example.com");
System.out.println(window.getResponseHeaders().toString());
}
}

private void formFillingTest(PlaywrightWindow window) throws NodeJsCodeException, InterruptedException {
String expected = "This is the expected value!";
String actual = null;
window.fill("id=input__text", expected);
actual = window.getDocument().getElementById("input__text").attr("value");
// TODO seems like it sets the text correctly. Just got to find another way of retrieving the value from the form.
Thread.sleep(60000);
window.fill("id=input__password", expected);
actual = window.getOuterHtml().getElementById("input__text").attr("value");
// TODO seems like it sets the text correctly.
// TODO Just got to find a way of retrieving the value from the form, because it wont work with the regular form.value thing.
//assertEquals(expected, actual);
}
}

0 comments on commit 3221a3a

Please sign in to comment.