| 44 | import com.microsoft.playwright.options.WaitForSelectorState; |
| 45 | |
| 46 | public abstract class PlaywrightWrapper extends HtmlReporter{ |
| 47 | |
| 48 | int retry = 0; |
| 49 | |
| 50 | /** |
| 51 | * Load the URL on the browser launched |
| 52 | * @author TestLeaf |
| 53 | * @param url The http(s) URL that to be loaded on the browser |
| 54 | * @return true if the load is successful else false |
| 55 | */ |
| 56 | public boolean navigate(String url) { |
| 57 | try { |
| 58 | getPage().navigate(url); |
| 59 | reportStep("The page with URL :"+url+" is loaded", "pass"); |
| 60 | } catch (PlaywrightException e) { |
| 61 | reportStep("PlaywrightException : \n" + e.getMessage(), "fail"); |
| 62 | } |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Maximize the browser based on screen size |
| 68 | * Presently there is no built-in method to invoke. |
| 69 | * @author TestLeaf |
| 70 | */ |
| 71 | public void maximize() { |
| 72 | try { |
| 73 | GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); |
| 74 | getPage().setViewportSize(gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight()); |
| 75 | } catch (HeadlessException e) { |
| 76 | |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Check if the given selector of the element is visible or not after 2 seconds |
| 82 | * @param locator The css / xpath / or playwright supported locator |
| 83 | * @return true if the element is visible else false |
| 84 | * @author TestLeaf |
| 85 | */ |
| 86 | public boolean isVisible(String locator) { |
| 87 | boolean bVisible = false; |
| 88 | try { |
| 89 | getPage().setDefaultTimeout(2000); |
| 90 | bVisible = getPage().isVisible(locator); |
| 91 | } catch (PlaywrightException e) { |
| 92 | } |
| 93 | getPage().setDefaultTimeout(ConfigurationManager.configuration().timeout()); |
| 94 | return bVisible; |
| 95 | |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Use this method to typing into an element, which may set its value. |
| 100 | * @param locator The locator to identify the element |
| 101 | * @param value The value to be entered in the text |
| 102 | * @param name The name of the text field (label) |
| 103 | * @return true if the value is typed else false |
nothing calls this directly
no outgoing calls
no test coverage detected