Skip to content

Commit

Permalink
Merge pull request #42 from ing-bank/feature/timeouts
Browse files Browse the repository at this point in the history
Timeouts and Delete with payload
  • Loading branch information
JPBorude08 authored Dec 17, 2024
2 parents 4dc7654 + cf0e743 commit 8ed8469
Show file tree
Hide file tree
Showing 23 changed files with 356 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.ing</groupId>
<artifactId>ingenious-playwright</artifactId>
<version>1.0</version>
<version>2.0</version>
</parent>
<artifactId>Common</artifactId>
<properties>
Expand Down
2 changes: 1 addition & 1 deletion Datalib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ing</groupId>
<artifactId>ingenious-playwright</artifactId>
<version>1.0</version>
<version>2.0</version>
</parent>
<artifactId>ingenious-datalib</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion Dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ing</groupId>
<artifactId>ingenious-playwright</artifactId>
<version>1.0</version>
<version>2.0</version>
</parent>
<artifactId>Dist</artifactId>
<packaging>pom</packaging>
Expand Down
4 changes: 2 additions & 2 deletions Engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.ing</groupId>
<artifactId>ingenious-playwright</artifactId>
<version>1.0</version>
<version>2.0</version>
</parent>
<artifactId>ingenious-engine</artifactId>
<packaging>jar</packaging>
Expand Down Expand Up @@ -214,7 +214,7 @@
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>${ioAppium.version}</version>
<version>${appium.version}</version>
<type>jar</type>
</dependency>
<dependency>
Expand Down
292 changes: 246 additions & 46 deletions Engine/src/main/java/com/ing/engine/commands/browser/Assertions.java

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions Engine/src/main/java/com/ing/engine/commands/browser/Basic.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,31 @@ public void storeElementValueinVariable() {
PlaywrightExceptionLogging(e);
}
}

@Action(object = ObjectType.PLAYWRIGHT, desc = "Store [<Object>] element's CSS value into Runtime variable: -> [<Data>]", input = InputType.YES, condition=InputType.YES)
public void storeElementCSSValueinVariable() {

String cssValue = "";
String strObj = Input;
try {
cssValue = (String) Locator.evaluate("(element) => window.getComputetStyle(element).getPropertyValue("+Condition+")");
if (strObj.matches(".*:.*")) {
String sheetName = strObj.split(":", 2)[0];
String columnName = strObj.split(":", 2)[1];
userData.putData(sheetName, columnName, cssValue);
Report.updateTestLog(Action, "Element's '"+Condition+"' value [" + cssValue + "] is stored in " + strObj, Status.DONE);
} else {
Report.updateTestLog(Action,
"Given input [" + Input + "] format is invalid. It should be [sheetName:ColumnName]",
Status.DEBUG);
}

} catch (Exception ex) {
Logger.getLogger(JSCommands.class.getName()).log(Level.SEVERE, null, ex);
Report.updateTestLog(Action, "Javascript execution failed", Status.DEBUG);

}
}

@Action(object = ObjectType.BROWSER, desc = "store variable value [<Condition>] in data sheet[<Data>]", input = InputType.YES, condition = InputType.YES)
public void storeVariableInDataSheet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void LocatorExecuteEval() {
}

@Action(object = ObjectType.BROWSER, desc = "To Store value from the JavaScript command", input = InputType.YES, condition=InputType.YES)
public void StoreEval() {
public void BrowserStoreEval() {
try {
String variableName = Condition;
String value = "";
Expand All @@ -70,6 +70,26 @@ public void StoreEval() {
}
}

@Action(object = ObjectType.PLAYWRIGHT, desc = "To Store value from the JavaScript command on a Locator", input = InputType.YES, condition=InputType.YES)
public void LocatorStoreEval() {
try {
String variableName = Condition;
String value = "";
if (variableName.matches("%.*%")) {
value = (String) Locator.evaluate(Data);
addVar(variableName, value);
Report.updateTestLog(Action, "JS evaluated value stored", Status.DONE);
} else {
Report.updateTestLog(Action, "Variable format is not correct", Status.DEBUG);
}

} catch (Exception ex) {
Logger.getLogger(JSCommands.class.getName()).log(Level.SEVERE, null, ex);
Report.updateTestLog(Action, "Javascript execution failed", Status.DEBUG);

}
}

@Action(object = ObjectType.PLAYWRIGHT, desc = "Click the [<Object>] using JavaScript ")
public void clickByJS() {
try {
Expand Down
28 changes: 24 additions & 4 deletions Engine/src/main/java/com/ing/engine/commands/browser/Switch.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ public Switch(CommandControl cc) {
@Action(object = ObjectType.PLAYWRIGHT, desc = "Switch to new Page", input = InputType.NO)
public void clickAndSwitchToNewPage() {
try {
Page popup = Page.waitForPopup(() -> {
Page.WaitForPopupOptions options = new Page.WaitForPopupOptions();
options.setTimeout(getTimeoutValue());

Page popup = Page.waitForPopup(options, () -> {
Locator.click();
});

BrowserContext = popup.context();
AObject.setPage(popup);
Page = popup;
Expand All @@ -35,8 +39,10 @@ public void clickAndSwitchToNewPage() {
@Action(object = ObjectType.BROWSER, desc = "Switch to new Page", input = InputType.YES)
public void createAndSwitchToNewPage() {
try {
Page.NavigateOptions options = new Page.NavigateOptions();
options.setTimeout(getTimeoutValue());
Page page = BrowserContext.newPage();
page.navigate(Data);
page.navigate(Data,options);
AObject.setPage(page);
Page = page;
Page.bringToFront();
Expand All @@ -56,11 +62,12 @@ public void createAndSwitchToNewContext() {
Browser.NewContextOptions newContextOptions = new Browser.NewContextOptions();
newContextOptions.setHttpCredentials(userName, Control.getCurrentProject().getProjectSettings().getUserDefinedSettings().getProperty(userName));
*/

Page.NavigateOptions options = new Page.NavigateOptions();
options.setTimeout(getTimeoutValue());
Browser browser = BrowserContext.browser();
BrowserContext = browser.newContext();
Page = BrowserContext.newPage();
Page.navigate(Data);
Page.navigate(Data,options);
AObject.setPage(Page);
Page.bringToFront();
Driver.setPage(Page);
Expand Down Expand Up @@ -185,4 +192,17 @@ public void switchToMainPage() {
}
}

private double getTimeoutValue(){
double timeout = 30000;
if(Condition != null || !Condition.isEmpty())
{
try {
timeout = Double.parseDouble(Condition.trim());
} catch (NumberFormatException e) {
Report.updateTestLog(Action,
"'"+Condition+"' cannot be converted to timeout of type Double", Status.DEBUG);
}
}
return timeout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.net.InetSocketAddress;
import java.net.ProxySelector;
import java.net.URI;
import javax.net.ssl.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -38,8 +37,6 @@
import java.net.http.HttpRequest.BodyPublisher;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.time.Duration;
import java.time.Instant;
import java.util.HashMap;
Expand Down Expand Up @@ -68,7 +65,8 @@ public enum RequestMethod {
PUT,
PATCH,
GET,
DELETE
DELETE,
DELETEWITHPAYLOAD
}

@Action(object = ObjectType.WEBSERVICE, desc = "PUT Rest Request ", input = InputType.YES, condition = InputType.OPTIONAL)
Expand Down Expand Up @@ -129,6 +127,16 @@ public void deleteRestRequest() {
e.printStackTrace();
}
}

@Action(object = ObjectType.WEBSERVICE, desc = "DELETE with Payload ", input = InputType.YES)
public void deleteWithPayload() {
try {
createhttpRequest(RequestMethod.DELETEWITHPAYLOAD);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@Action(object = ObjectType.WEBSERVICE, desc = "Assert Response Code ", input = InputType.YES)
public void assertResponseCode() {
Expand Down Expand Up @@ -657,7 +665,7 @@ private String urlencodedParams() {
try {
ArrayList<String> params = urlParams.get(key);
for (String param : params) {
parameters.put(param.split("=")[0], param.split("=")[1]);
parameters.put(param.split("=",2)[0], param.split("=",2)[1]);
}
urlParamString = parameters.entrySet()
.stream()
Expand Down Expand Up @@ -821,6 +829,10 @@ private void setRequestMethod(String method, String payload) {
httpRequestBuilder.put(key, httpRequestBuilder.get(key).DELETE());
break;
}
case "DELETEWITHPAYLOAD": {
httpRequestBuilder.put(key, httpRequestBuilder.get(key).DELETE());
break;
}

}
headers.remove(key);
Expand All @@ -831,7 +843,7 @@ private void setRequestMethod(String method, String payload) {
}

private void setRequestMethod(RequestMethod requestmethod) throws FileNotFoundException {
if (requestmethod.toString().equals("PUT") || requestmethod.toString().equals("POST") || requestmethod.toString().equals("PATCH")) {
if (requestmethod.toString().equals("PUT") || requestmethod.toString().equals("POST") || requestmethod.toString().equals("PATCH") || requestmethod.toString().equals("DELETEWITHPAYLOAD")) {

setRequestMethod(requestmethod.toString(), handlePayloadorEndpoint(Data));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public void launchDriver(RunContext context) throws UnCaughtException {
System.out.println("Launching " + runContext.BrowserName);
try {
playwright = WebDriverFactory.createPlaywright();

if(Control.getCurrentProject().getProjectSettings().getUserDefinedSettings().containsKey("testIdAttribute"))
{
playwright.selectors().setTestIdAttribute(Control.getCurrentProject().getProjectSettings().getUserDefinedSettings().getProperty("testIdAttribute"));
}

BrowserType browserType = (BrowserType) WebDriverFactory.createBrowserType(playwright,runContext.BrowserName, context, Control.getCurrentProject().getProjectSettings());
if (Control.exe.getExecSettings().getRunSettings().isGridExecution()) {
System.out.println("Launching Remote Driver");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.ing.engine.core.RunContext;
import com.ing.engine.reporting.util.DateTimeUtils;
import java.io.File;
import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
Expand Down
2 changes: 1 addition & 1 deletion IDE/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ing</groupId>
<artifactId>ingenious-playwright</artifactId>
<version>1.0</version>
<version>2.0</version>
</parent>
<artifactId>ingenious-ide</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private boolean isProtractorjsStep(TestStep step) {

private boolean isRestWebservicePostStep(TestStep step) {
return step != null && step.isWebserviceStep()
&& (step.getAction().contains("postRest") || step.getAction().contains("putRest") || step.getAction().contains("patchRest"));
&& (step.getAction().contains("postRest") || step.getAction().contains("putRest") || step.getAction().contains("patchRest") || step.getAction().contains("deleteWithPayload"));
}

private boolean isSetEndPointStep(TestStep step) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
Expand Down Expand Up @@ -885,16 +886,16 @@ protected JMenuItem create(String name, KeyStroke keyStroke) {
return menuItem;
}

private void setCCP() {
private void setCCP() {
TransferActionListener actionListener = new TransferActionListener();
cut = new JMenuItem("Cut");
cut.setActionCommand((String) TransferHandler.getCutAction().getValue(Action.NAME));
cut.addActionListener(actionListener);
cut.setAccelerator(Keystroke.CUT);
cut.setMnemonic(KeyEvent.VK_T);
add(cut);

copy = new JMenuItem("Copy");
copy = new JMenuItem("Copy");
copy.setActionCommand((String) TransferHandler.getCopyAction().getValue(Action.NAME));
copy.addActionListener(actionListener);
copy.setAccelerator(Keystroke.COPY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class Keystroke {

private static final int SHORTCUT = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
private static final int SHORTCUT = Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx();
public static final KeyStroke DELETE = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
RENAME = KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0),
CUT = KeyStroke.getKeyStroke(KeyEvent.VK_X, SHORTCUT),
Expand Down
Binary file modified IDE/src/main/resources/ui/resources/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IDE/src/main/resources/ui/resources/favicon1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified IDE/src/main/resources/ui/resources/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion StoryWriter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ing</groupId>
<artifactId>ingenious-playwright</artifactId>
<version>1.0</version>
<version>2.0</version>
</parent>
<artifactId>storywriter</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion TestData - Csv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.ing</groupId>
<artifactId>ingenious-playwright</artifactId>
<version>1.0</version>
<version>2.0</version>
</parent>
<artifactId>ingenious-testdata-csv</artifactId>
<packaging>jar</packaging>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ing</groupId>
<artifactId>ingenious-playwright</artifactId>
<version>1.0</version>
<version>2.0</version>
<packaging>pom</packaging>
<modules>
<module>StoryWriter</module>
Expand Down Expand Up @@ -55,7 +55,7 @@
<httpcore.version>4.4.16</httpcore.version>
<guava.version>32.0.1-jre</guava.version>
<mac.version>mac-aarch64</mac.version>
<ioAppium.version>LATEST</ioAppium.version>
<appium.version>LATEST</appium.version>
<setupDir>../Dist/release</setupDir>
<resourceDir>../Resources</resourceDir>

Expand Down

0 comments on commit 8ed8469

Please sign in to comment.