Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/make inbound message generation more robust #5

Closed
wants to merge 176 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
510a2d8
Merge pull request #1 from citrusframework/main
bbortt Sep 3, 2021
a742254
Merge branch 'citrusframework:main' into master
bbortt Oct 12, 2021
e8f0f00
Merge branch 'citrusframework:main' into master
tschlat Dec 13, 2021
13cd181
Merge branch 'citrusframework:main' into master
bbortt Mar 29, 2022
620703a
chore: Use alphabetic order of dependency versions in POM
christophd May 3, 2022
4f26333
chore: select random kafka port by default
bbortt Apr 21, 2022
70ce977
chore(deps): kafka version 3.2.0
bbortt May 12, 2022
08c1cf4
Merge branch 'main' of github.com:citrusframework/citrus into main
christophd May 16, 2022
1e9bc89
chore(deps): Bump spring-core from 5.3.19 to 5.3.20
dependabot[bot] May 25, 2022
9e658d2
Merge pull request #860 from citrusframework/dependabot/maven/org.spr…
bbortt May 29, 2022
5325a86
fix(#857): Add Groovy test runtime
christophd May 4, 2022
1e52b87
chore: Improve sleep action builder methods
christophd May 17, 2022
32b8e70
chore: Fix obsolete jaxb-core dependency
christophd May 19, 2022
4bee507
chore: Introduce type alias resolver resource path lookup
christophd May 19, 2022
6eabb18
chore: Make Spring oxm marshaller dependency optional
christophd May 19, 2022
fc3ba4a
fix(#859): Update default SshServer host key to RSA
christophd May 19, 2022
c04dec5
fix(#857): Make sure to replace dynamic content when setting variable…
christophd May 24, 2022
91b9ad6
fix(#857): Introduce Groovy type converter to support GString impleme…
christophd May 24, 2022
7c181c8
fix(#857): Introduce generic test source annotation
christophd Jun 7, 2022
a504e11
fix(#857): Incorporate review changes
christophd Jun 20, 2022
6551b7e
chore(build): Assume gnu-sed usage for MacOS users
christophd Jun 27, 2022
2fe3e3f
chore(deps): Bump jackson version to v2.13.3
christophd Jun 29, 2022
83cbecd
chore: Add spring-test module when using citrus-spring
christophd Jun 30, 2022
5a9b6f6
chore: Avoid misleading type converter lookup warnings
christophd Jul 1, 2022
8061e1f
issues/697
akuz0 Jul 10, 2022
9fbeab7
issues/697
akuz0 Jul 10, 2022
63c6049
Merge pull request #870 from akuz0/unixTimestamp
bbortt Jul 11, 2022
74a6207
fix(#857): Add test action builder lookup
christophd Jul 18, 2022
9acb1ad
fix(#861): Refactor wait action builder
christophd Jul 27, 2022
61e0b7a
fix(#879): Avoid concurrent modification exception when evaluating te…
christophd Aug 24, 2022
29293ac
chore(build): Fix flaky JMS tests
christophd Aug 26, 2022
ed2bccd
chore(build): Fix flaky SQL query retries tests
christophd Aug 26, 2022
54afadc
fix(#804): Add plain XML runtime
christophd Oct 1, 2021
8e954c6
fix(#804): Refactor test method invocation
christophd Jul 26, 2022
3c7a8ae
fix(#804): Add send/receive test actions to XML runtime
christophd Aug 1, 2022
cdfbc88
fix(#804): Add test action containers to XML runtime
christophd Aug 5, 2022
165d074
fix(#804): Add test actions to XML runtime
christophd Aug 8, 2022
bc9241b
fix(#804): Add generic test action support to XML runtime
christophd Aug 8, 2022
64c9fcd
fix(#804): Add test actions to XML runtime
christophd Aug 8, 2022
f9a9a1a
fix(#804): Add apply template support to XML runtime
christophd Aug 9, 2022
484da80
fix(#804): Add custom test action support to XML runtime
christophd Aug 10, 2022
126bec7
fix(#804): Add transform action to XML runtime
christophd Aug 10, 2022
29d23b3
fix(#804): Add groovy action to XML runtime
christophd Aug 10, 2022
7c63087
fix(#804): Fix unit tests on template action
christophd Aug 10, 2022
9661213
fix(#804): Add Http based actions to XML runtime
christophd Aug 16, 2022
8660728
chore: Fix NPE when processing Http HEAD requests
christophd Aug 17, 2022
794dfc1
fix(#804): Reuse send/receive builder configuration logic in Http act…
christophd Aug 17, 2022
0f9bb17
fix(#804): Use XML namespace and schema for XML runtime
christophd Aug 24, 2022
fe9b269
chore(build): Fix flaky SQL query retries tests
christophd Aug 26, 2022
71e2271
Add Spring schemas for 3.3.0
christophd Aug 26, 2022
2dcc071
Update project metadata for 3.3.0
christophd Aug 26, 2022
ec2ee06
Use 3.3.0-SNAPSHOT version in Spring schemas
christophd Aug 26, 2022
9350b67
Use next snapshot version 3.4.0-SNAPSHOT
christophd Aug 26, 2022
7fe1b87
Use next snapshot version 3.4.0-SNAPSHOT
christophd Aug 26, 2022
1f7f876
Add docs version for 3.3.0
christophd Aug 26, 2022
16a4279
chore: Add citrus-xml module to BOM
christophd Sep 14, 2022
eb2aeb5
chore(#885): default test loader supports fluent configuration
bbortt Sep 6, 2022
7364224
fix(#885): respect citrus context in default test loader
bbortt Sep 6, 2022
0e85779
fix(#894): Avoid NullpointerException in citrus:env function
christophd Sep 28, 2022
efb325b
chore(deps): Bump snakeyaml in /vintage/citrus-arquillian
dependabot[bot] Dec 14, 2022
31b8253
Merge pull request #908 from citrusframework/dependabot/maven/vintage…
bbortt Dec 25, 2022
3b353c7
chore(deps): Bump hsqldb from 2.6.1 to 2.7.1
dependabot[bot] Dec 25, 2022
5228e56
Merge pull request #909 from citrusframework/dependabot/maven/org.hsq…
bbortt Dec 28, 2022
67880a3
Add Spring schemas for 3.3.1
christophd Jan 10, 2023
346d1a1
Update project metadata for 3.3.1
christophd Jan 10, 2023
c06b66e
Use 3.4.0-SNAPSHOT version in Spring schemas
christophd Jan 10, 2023
0d0c754
Merge branch 'main' of github.com:citrusframework/citrus
christophd Jan 10, 2023
638ccaf
fix(#893): Add YAML runtime
christophd Jan 11, 2023
0f62a7e
fix(#887): Use standalone bom
christophd Jan 19, 2023
571f629
chore: Spring context improvements
christophd Jan 20, 2023
74ddff9
fix(#892): Support multiple jsonPath validations
christophd Jan 23, 2023
790174b
fix(#893): Enhance YAML runtime
christophd Jan 24, 2023
f5270d4
chore(deps): Update dependencies
christophd Jan 24, 2023
87235a9
fix(#846): Always debug log received message content
christophd Jan 25, 2023
e952b81
chore: Fix documentation overview versions
christophd Jan 26, 2023
e5bf5db
chore: Fix standalone Citrus BOM
christophd Jan 26, 2023
11e0220
chore: Add required information to standalone Citrus BOM
christophd Jan 27, 2023
49f9b90
chore: Update nexus-staging-maven-plugin to 1.6.13
christophd Jan 27, 2023
6f4e72c
Add Spring schemas for 3.4.0
christophd Jan 28, 2023
8df484d
Update project metadata for 3.4.0
christophd Jan 28, 2023
ec5d652
Use 3.4.0-SNAPSHOT version in Spring schemas
christophd Jan 28, 2023
9f046b9
Use next snapshot version 3.5.0-SNAPSHOT
christophd Jan 28, 2023
c8cc657
chore: Update docs overview for 3.4.0 release
christophd Jan 28, 2023
3c308d1
Use next snapshot version 3.5.0-SNAPSHOT
christophd Jan 28, 2023
9d0e01f
chore: Improve Groovy actions script handling
christophd Feb 8, 2023
ee539a2
fix(#924): Fix false positive test report in DefaultTestLoader
christophd Feb 9, 2023
4ee7734
chore: Improve Groovy endpoint script handling
christophd Feb 9, 2023
689cb6c
ci: add jdk17 main build
bbortt Dec 7, 2022
e4e8ab1
feat(spring): upgrade to 6.0.0 release
bbortt Dec 7, 2022
755a327
chore(deps): Use Jakarta EE
christophd Apr 19, 2022
3e12fb7
fix(#922): Citrus 4.0 refactoring
christophd Mar 17, 2023
2f230d1
Merge branch 'feature/spring-600-upgrade' into chore/jakarta-update
christophd Mar 20, 2023
a397852
fix(#922): Use Citrus 4.0.0-SNAPSHOT
christophd Mar 20, 2023
1d508ee
Merge branch 'chore/jakarta-update' into issue/922/citrus-4.0
christophd Mar 20, 2023
3f6179c
fix(#922): Fix Java version in Maven archetypes
christophd Mar 20, 2023
5c180c6
fix(#922): Remove obsolete Selenium exclusions
christophd Mar 20, 2023
e2e4295
fix(#922): Run LTS build nightly
christophd Mar 20, 2023
0701cdc
Fix code formatting
christophd Mar 21, 2023
52c1daa
Merge pull request #932 from citrusframework/issue/922/citrus-4.0
christophd Mar 21, 2023
2b59252
Changed the default citrus suite name passed to beforeSuite and after…
tko-qs Mar 22, 2023
4fe7e96
chore: Update README
christophd Mar 23, 2023
04637fe
fix(#922): Move citrus-jdbc module to citrus-db project
christophd Mar 21, 2023
b33d435
chore(deps): Bump spring-core from 6.0.6 to 6.0.7
dependabot[bot] Mar 23, 2023
256f31a
Merge pull request #937 from citrusframework/dependabot/maven/org.spr…
bbortt Mar 24, 2023
6ba1bfe
chore(#938) Update artifact group id
bbortt Mar 24, 2023
04f1616
chore(#938): Update packages in spring.schemas
christophd Mar 27, 2023
d465b59
chore(#938): Update URLs to citrusframework.org
christophd Mar 28, 2023
416f2d7
chore(#922): Move citrus-remote module to separate repository
christophd Apr 20, 2023
1677f26
chore(#922): Remove obsolete dependencies
christophd Apr 21, 2023
1b613a1
Add Spring schemas for 4.0.0-M1
christophd Apr 21, 2023
3c1c2e1
Update project metadata for 4.0.0-M1
christophd Apr 21, 2023
e9c4191
Use 4.0.0-SNAPSHOT version in Spring schemas
christophd Apr 21, 2023
bf230bd
feat(#922): remove vintage modules
bbortt Apr 21, 2023
a3f42f0
Merge pull request #946 from citrusframework/feature/922-remove-legac…
bbortt Jun 14, 2023
eabdc24
chore(deps): Bump guava from 31.1-jre to 32.0.0-jre
dependabot[bot] Jun 14, 2023
082f0bb
chore(deps): Bump snappy-java from 1.1.9.1 to 1.1.10.1
dependabot[bot] Jun 15, 2023
8778ba7
Merge pull request #952 from citrusframework/dependabot/maven/org.xer…
bbortt Jun 18, 2023
74b8c97
Merge pull request #951 from citrusframework/dependabot/maven/com.goo…
bbortt Jun 18, 2023
c5e8a36
Detect if the current execution is started from a jar, and if so anal…
turing85 May 17, 2023
96aefb0
chore(#922): Add TestBehaviorExecutingEndpointAdapter
christophd Jul 6, 2023
c862b8b
chore(#922): Add unit test coverage from removed java-dsl module
christophd Jul 7, 2023
3f6d5f3
chore(deps): Bump sshd-sftp from 2.9.2 to 2.10.0
dependabot[bot] Jul 10, 2023
04985e6
Merge pull request #955 from citrusframework/dependabot/maven/org.apa…
bbortt Jul 11, 2023
e5ab21f
chore: Add more Groovy test DSL unit tests
christophd Jul 10, 2023
0980261
chore: Add apply template support to Groovy DSL
christophd Jul 13, 2023
e4ada56
chore: Add more Groovy test DSL unit tests
christophd Jul 16, 2023
0433972
chore: Refactor Groovy test action DSL
christophd Jul 19, 2023
1bbfd25
chore: Add Apache Camel YAML action DSL support
christophd Jul 19, 2023
86f0a06
chore: Add Apache Camel XML action DSL support
christophd Jul 20, 2023
08a4f8c
chore: Add Apache Camel Groovy action DSL unit tests
christophd Jul 20, 2023
698dc7f
chore: Add JMS YAML action DSL support
christophd Jul 20, 2023
bc719c8
chore: Add JMS XML action DSL support
christophd Jul 20, 2023
7e48896
chore: Add JMS Groovy action DSL unit tests
christophd Jul 20, 2023
accd543
chore: Add SOAP WebService YAML action DSL support
christophd Jul 21, 2023
fce61af
chore: Add SOAP WebService XML action DSL support
christophd Jul 24, 2023
dbbde17
chore: Add Selenium YAML action DSL support
christophd Jul 25, 2023
2d646fd
chore: Add Selenium XML action DSL support
christophd Jul 26, 2023
4f4e993
chore: Add SpringIntegration YAML action DSL support
christophd Jul 26, 2023
875ae9b
chore: Add SpringIntegration XML action DSL support
christophd Jul 26, 2023
e19c95a
chore: Add SOAP WebServices Groovy action DSL support
christophd Jul 26, 2023
37c746b
chore: Add SQL Groovy action DSL support
christophd Jul 26, 2023
8d16ff6
chore: Add Spring Integration Groovy action DSL support
christophd Jul 26, 2023
6a90264
chore: Add Selenium Groovy action DSL support
christophd Jul 26, 2023
c4795f7
chore(deps): Bump dependency versions
christophd Jul 27, 2023
64b2498
chore(docs): Update Citrus documentation
christophd Aug 9, 2023
73c4c28
ci: fix fullbuild on windows
bbortt Jul 27, 2023
ce6c750
feat(citrus-validation-json): uses the networknt/json-schema-validato…
bbortt Aug 14, 2023
f16907b
fix(citrus-simulator): citrus-simulator compatibility
bbortt Jul 30, 2023
d45f060
ci: run main build on all pull-requests
bbortt Aug 14, 2023
bbf18cf
chore(deps): Fix Jakarta activation API usage
christophd Aug 16, 2023
11b2844
chore(ci): Use ubuntu-latest and Eclipse temurin Java 17
christophd Aug 17, 2023
69ba1ee
ci: windows build fix
bbortt Aug 18, 2023
b0db831
Fix some typos and grammatical issues
picimako Aug 19, 2023
832d44f
Fix documentation section anchors
picimako Aug 19, 2023
841439c
Fix a few minor code snippet issues
picimako Aug 21, 2023
2b8405e
chore(deps): Upgrade Camel from 4.0.0-CR1 to 4.0.0
apupier Aug 21, 2023
4ae1753
Align prerequisites in contributing guide to the readme
apupier Aug 21, 2023
dd8d576
Remove Travis reference from Contributing guide
apupier Aug 21, 2023
714dc16
fix(#965): Fix TransformAction builder charset setting on xslt resource
christophd Aug 31, 2023
909a840
chore(docs): Update Citrus documentation
christophd Aug 31, 2023
46a0c7a
chore(deps): Revert GPG Maven plugin version
christophd Aug 31, 2023
c4f457b
chore(deps): Revert Maven source plugin version
christophd Aug 31, 2023
46c788f
chore(deps): Try to fix Sonatype Nexus Staging release plugin on JDK17
christophd Aug 31, 2023
94635b7
Add Spring schemas for 4.0.0-M2
christophd Aug 31, 2023
c5c602e
Update project metadata for 4.0.0-M2
christophd Aug 31, 2023
2bef828
Use 4.0.0-SNAPSHOT version in Spring schemas
christophd Aug 31, 2023
2f804e4
Merge branch 'citrusframework:main' into master
tschlat Sep 4, 2023
dfe5e2c
chore(junit): Fix reported test names when running tests with JUnit 4
christophd Sep 5, 2023
1252851
chore(junit5): Fix after suite handling
christophd Sep 5, 2023
138e573
fix: expose test contest to inheritant test case runners
bbortt Aug 31, 2023
3cf2480
feat: static access to extractor builders
bbortt Sep 5, 2023
67532c8
feat(#973): Allow deactivation of standard LoggingReporter
Sep 7, 2023
c42ddbb
feat(#973): Allow deactivation of standard LoggingReporter
Sep 7, 2023
4058578
Merge pull request #975 from citrusframework/issue/973/standard-repor…
bbortt Sep 8, 2023
5e9b3d5
Merge branch 'citrusframework:main' into master
tschlat Sep 8, 2023
39f64ed
fix: Allow custom http status codes
Sep 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: Add Selenium Groovy action DSL support
christophd committed Jul 27, 2023
commit 6a9026417ca2528e70dec3c91b705cc7a6f3da51
30 changes: 18 additions & 12 deletions connectors/citrus-selenium/pom.xml
Original file line number Diff line number Diff line change
@@ -51,18 +51,6 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-yaml</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-xml</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<!-- Selenium -->
<dependency>
@@ -132,5 +120,23 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-groovy</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-yaml</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-xml</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -108,6 +108,16 @@ public AlertAction.Builder alert() {
return builder;
}

/**
* Navigate action.
*/
public NavigateAction.Builder navigate() {
NavigateAction.Builder builder = new NavigateAction.Builder()
.browser(seleniumBrowser);
this.delegate = builder;
return builder;
}

/**
* Navigate action.
*/
@@ -184,6 +194,26 @@ public SetInputAction.Builder setInput(String value) {
return builder;
}

/**
* Set input action.
*/
public SetInputAction.Builder setInput() {
SetInputAction.Builder builder = new SetInputAction.Builder()
.browser(seleniumBrowser);
this.delegate = builder;
return builder;
}

/**
* Check input action.
*/
public CheckInputAction.Builder checkInput() {
CheckInputAction.Builder builder = new CheckInputAction.Builder()
.browser(seleniumBrowser);
this.delegate = builder;
return builder;
}

/**
* Check input action.
*/
@@ -246,6 +276,16 @@ public MakeScreenshotAction.Builder screenshot(String outputDir) {
return builder;
}

/**
* Store file.
*/
public StoreFileAction.Builder store() {
StoreFileAction.Builder builder = new StoreFileAction.Builder()
.browser(seleniumBrowser);
this.delegate = builder;
return builder;
}

/**
* Store file.
* @param filePath
@@ -258,6 +298,16 @@ public StoreFileAction.Builder store(String filePath) {
return builder;
}

/**
* Get stored file.
*/
public GetStoredFileAction.Builder getStored() {
GetStoredFileAction.Builder builder = new GetStoredFileAction.Builder()
.browser(seleniumBrowser);
this.delegate = builder;
return builder;
}

/**
* Get stored file.
* @param fileName
@@ -280,6 +330,16 @@ public WaitUntilAction.Builder waitUntil() {
return builder;
}

/**
* Execute JavaScript.
*/
public JavaScriptAction.Builder javascript() {
JavaScriptAction.Builder builder = new JavaScriptAction.Builder()
.browser(seleniumBrowser);
this.delegate = builder;
return builder;
}

/**
* Execute JavaScript.
*/
@@ -343,6 +403,16 @@ public SwitchWindowAction.Builder focus() {
return builder;
}

/**
* Switch window.
*/
public SwitchWindowAction.Builder switchWindow() {
SwitchWindowAction.Builder builder = new SwitchWindowAction.Builder()
.browser(seleniumBrowser);
this.delegate = builder;
return builder;
}

@Override
public SeleniumAction build() {
Assert.notNull(delegate, "Missing delegate action to build");
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2022 the original author or authors.
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.citrusframework.selenium.groovy;

import org.citrusframework.Citrus;
import org.citrusframework.CitrusContext;
import org.citrusframework.CitrusInstanceManager;
import org.citrusframework.DefaultTestCaseRunner;
import org.citrusframework.annotations.CitrusAnnotations;
import org.citrusframework.context.StaticTestContextFactory;
import org.citrusframework.context.TestContext;
import org.citrusframework.groovy.GroovyTestLoader;
import org.citrusframework.testng.AbstractTestNGUnitTest;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeClass;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.when;

/**
* @author Christoph Deppisch
*/
public class AbstractGroovyActionDslTest extends AbstractTestNGUnitTest {

protected Citrus citrus;

@Mock
protected CitrusContext citrusContext;

@BeforeClass
public void setupMocks() {
MockitoAnnotations.openMocks(this);
citrus = CitrusInstanceManager.newInstance(() -> citrusContext);
}

@Override
protected TestContext createTestContext() {
TestContext context = super.createTestContext();
doAnswer(invocation -> {
context.getReferenceResolver().bind(invocation.getArgument(0, String.class), invocation.getArgument(1));
return null;
}).when(citrusContext).bind(any(String.class), any());

when(citrusContext.getReferenceResolver()).thenReturn(context.getReferenceResolver());
when(citrusContext.getMessageValidatorRegistry()).thenReturn(context.getMessageValidatorRegistry());
when(citrusContext.getTestContextFactory()).thenReturn(new StaticTestContextFactory(context));
CitrusAnnotations.injectAll(this, citrus, context);
return context;
}

protected GroovyTestLoader createTestLoader(String sourcePath) {
GroovyTestLoader testLoader = new GroovyTestLoader().source(sourcePath);
CitrusAnnotations.injectAll(testLoader, citrus, context);
CitrusAnnotations.injectTestRunner(testLoader, new DefaultTestCaseRunner(context));

return testLoader;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
/*
* Copyright 2022 the original author or authors.
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.citrusframework.selenium.groovy;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.citrusframework.TestCase;
import org.citrusframework.TestCaseMetaInfo;
import org.citrusframework.groovy.GroovyTestLoader;
import org.citrusframework.selenium.actions.*;
import org.citrusframework.selenium.endpoint.SeleniumBrowser;
import org.citrusframework.selenium.endpoint.SeleniumBrowserConfiguration;
import org.citrusframework.selenium.model.PageValidator;
import org.citrusframework.selenium.model.WebPage;
import org.citrusframework.selenium.pages.UserFormPage;
import org.mockito.Mock;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

/**
* @author Christoph Deppisch
*/
public class SeleniumTest extends AbstractGroovyActionDslTest {

@Mock
private SeleniumBrowser browser;

@Mock
private HtmlUnitDriver webDriver;

@Mock
private WebDriver.TargetLocator targetLocator;

@Mock
private Alert alert;

@Mock
private WebElement webElement;

@Mock
private WebElement option;

@Mock
private WebPage webPage;

@Mock
private PageValidator<?> pageValidator;

@Mock
private WebDriver.Navigation navigation;

@Mock
private WebDriver.Options options;

@BeforeClass
@Override
public void setupMocks() {
super.setupMocks();

SeleniumBrowserConfiguration configuration = new SeleniumBrowserConfiguration();
when(browser.getEndpointConfiguration()).thenReturn(configuration);
when(browser.getName()).thenReturn("seleniumBrowser");
when(browser.getWebDriver()).thenReturn(webDriver);
when(webDriver.switchTo()).thenReturn(targetLocator);
when(targetLocator.alert()).thenReturn(alert);
when(alert.getText()).thenReturn("This is a warning message!");
when(webDriver.findElement(any(By.class))).thenReturn(webElement);
when(webElement.getText()).thenReturn("Ok");
when(webElement.isDisplayed()).thenReturn(true, true, true, true, true, true, true, true, true, true, true, true, true)
.thenReturn(false);
when(webElement.isEnabled()).thenReturn(true);
when(webElement.getAttribute("type")).thenReturn("submit");
when(webElement.getAttribute("value")).thenReturn("Foo");
when(webElement.getAttribute("enabled")).thenReturn("true");
when(webElement.getCssValue("color")).thenReturn("#000000");
when(webElement.getTagName()).thenReturn("button", "select");
when(webElement.findElements(any(By.class))).thenReturn(List.of(option));
when(option.isEnabled()).thenReturn(true);
when(option.getText()).thenReturn("new-value");
when(webDriver.executeScript(any(String.class), any(Object[].class))).thenReturn(Collections.emptyList()).thenReturn(List.of("Something went wrong"));
when(webDriver.navigate()).thenReturn(navigation);
when(webDriver.getWindowHandles()).thenReturn(Set.of("switchWindow", "closeWindow")).thenReturn(Set.of("newWindow", "switchWindow", "closeWindow"));
when(webDriver.getWindowHandle()).thenReturn("newWindow", "switchWindow", "closeWindow");
when(targetLocator.window(any(String.class))).thenReturn(webDriver);
when(browser.getStoredFile(any(String.class))).thenReturn("file.txt");
when(webDriver.manage()).thenReturn(options);
}

@Test
public void shouldLoadSeleniumActions() throws IOException {
GroovyTestLoader testLoader = createTestLoader("classpath:org/citrusframework/selenium/groovy/selenium.test.groovy");

context.getReferenceResolver().bind("seleniumBrowser", browser);
context.getReferenceResolver().bind("userForm", webPage);
context.getReferenceResolver().bind("pageValidator", pageValidator);

context.setVariable("switchWindow", "switchWindow");
context.setVariable("closeWindow", "closeWindow");

testLoader.load();

TestCase result = testLoader.getTestCase();
Assert.assertEquals(result.getName(), "SeleniumTest");
Assert.assertEquals(result.getMetaInfo().getAuthor(), "Christoph");
Assert.assertEquals(result.getMetaInfo().getStatus(), TestCaseMetaInfo.Status.FINAL);
Assert.assertEquals(result.getActionCount(), 23L);

int actionIndex = 0;

StartBrowserAction startAction = (StartBrowserAction) result.getTestAction(actionIndex++);
Assert.assertNotNull(startAction.getBrowser());
Assert.assertEquals(startAction.getName(), "selenium:start");

AlertAction alertAction = (AlertAction) result.getTestAction(actionIndex++);
Assert.assertNull(alertAction.getBrowser());
Assert.assertEquals(alertAction.getName(), "selenium:alert");
Assert.assertNull(alertAction.getText());
Assert.assertTrue(alertAction.isAccept());

alertAction = (AlertAction) result.getTestAction(actionIndex++);
Assert.assertNull(alertAction.getBrowser());
Assert.assertEquals(alertAction.getName(), "selenium:alert");
Assert.assertEquals(alertAction.getText(), "This is a warning message!");
Assert.assertFalse(alertAction.isAccept());

FindElementAction findElementAction = (FindElementAction) result.getTestAction(actionIndex++);
Assert.assertNull(findElementAction.getBrowser());
Assert.assertEquals(findElementAction.getName(), "selenium:find");
Assert.assertEquals(findElementAction.getBy().toString(), "By.className: clickable");
Assert.assertEquals(findElementAction.getTagName(), "button");
Assert.assertEquals(findElementAction.getText(), "Ok");
Assert.assertEquals(findElementAction.getAttributes().size(), 1L);
Assert.assertEquals(findElementAction.getAttributes().get("type"), "submit");
Assert.assertEquals(findElementAction.getStyles().size(), 1L);
Assert.assertEquals(findElementAction.getStyles().get("color"), "#000000");
Assert.assertTrue(findElementAction.isDisplayed());
Assert.assertTrue(findElementAction.isEnabled());

PageAction pageAction = (PageAction) result.getTestAction(actionIndex++);
Assert.assertNull(pageAction.getBrowser());
Assert.assertEquals(pageAction.getName(), "selenium:page");
Assert.assertEquals(pageAction.getAction(), "setUserName");
Assert.assertEquals(pageAction.getPage(), context.getReferenceResolver().resolve("userForm"));
Assert.assertNull(pageAction.getType());
Assert.assertEquals(pageAction.getArguments().size(), 1L);
Assert.assertEquals(pageAction.getArguments().get(0), "${username}");
Assert.assertNull(pageAction.getValidator());

pageAction = (PageAction) result.getTestAction(actionIndex++);
Assert.assertNull(pageAction.getBrowser());
Assert.assertEquals(pageAction.getName(), "selenium:page");
Assert.assertEquals(pageAction.getAction(), "validate");
Assert.assertNull(pageAction.getPage());
Assert.assertEquals(pageAction.getType(), UserFormPage.class.getName());
Assert.assertEquals(pageAction.getArguments().size(), 0L);
Assert.assertEquals(pageAction.getValidator(), context.getReferenceResolver().resolve("pageValidator"));

ClickAction clickAction = (ClickAction) result.getTestAction(actionIndex++);
Assert.assertNull(clickAction.getBrowser());
Assert.assertEquals(clickAction.getName(), "selenium:click");
Assert.assertEquals(clickAction.getBy().toString(), "By.id: edit-link");

HoverAction hoverAction = (HoverAction) result.getTestAction(actionIndex++);
Assert.assertNull(hoverAction.getBrowser());
Assert.assertEquals(hoverAction.getName(), "selenium:hover");
Assert.assertEquals(hoverAction.getBy().toString(), "By.id: edit-link");

SetInputAction setInputAction = (SetInputAction) result.getTestAction(actionIndex++);
Assert.assertNull(setInputAction.getBrowser());
Assert.assertEquals(setInputAction.getName(), "selenium:set-input");
Assert.assertEquals(setInputAction.getBy().toString(), "By.tagName: input");
Assert.assertEquals(setInputAction.getValue(), "new-value");

CheckInputAction checkInputAction = (CheckInputAction) result.getTestAction(actionIndex++);
Assert.assertNull(checkInputAction.getBrowser());
Assert.assertEquals(checkInputAction.getName(), "selenium:check-input");
Assert.assertEquals(checkInputAction.getBy().toString(), "By.xpath: //input[@type: 'checkbox']");
Assert.assertTrue(checkInputAction.isChecked());

DropDownSelectAction dropDownSelect = (DropDownSelectAction) result.getTestAction(actionIndex++);
Assert.assertNull(dropDownSelect.getBrowser());
Assert.assertEquals(dropDownSelect.getName(), "selenium:dropdown-select");
Assert.assertEquals(dropDownSelect.getBy().toString(), "By.name: gender");
Assert.assertEquals(dropDownSelect.getOption(), "male");
Assert.assertEquals(dropDownSelect.getOptions().size(), 0L);

DropDownSelectAction dropDownMultiSelect = (DropDownSelectAction) result.getTestAction(actionIndex++);
Assert.assertNull(dropDownMultiSelect.getBrowser());
Assert.assertEquals(dropDownMultiSelect.getName(), "selenium:dropdown-select");
Assert.assertEquals(dropDownMultiSelect.getBy().toString(), "By.id: title");
Assert.assertNull(dropDownMultiSelect.getOption());
Assert.assertEquals(dropDownMultiSelect.getOptions().size(), 2L);

WaitUntilAction waitUntilAction = (WaitUntilAction) result.getTestAction(actionIndex++);
Assert.assertNull(waitUntilAction.getBrowser());
Assert.assertEquals(waitUntilAction.getName(), "selenium:wait");
Assert.assertEquals(waitUntilAction.getBy().toString(), "By.id: dialog");
Assert.assertEquals(waitUntilAction.getCondition(), "hidden");

JavaScriptAction javaScriptAction = (JavaScriptAction) result.getTestAction(actionIndex++);
Assert.assertNull(javaScriptAction.getBrowser());
Assert.assertEquals(javaScriptAction.getName(), "selenium:javascript");
Assert.assertEquals(javaScriptAction.getScript(), "alert('This is awesome!')");
Assert.assertEquals(javaScriptAction.getExpectedErrors().size(), 1L);
Assert.assertEquals(javaScriptAction.getExpectedErrors().get(0), "Something went wrong");

MakeScreenshotAction screenshotAction = (MakeScreenshotAction) result.getTestAction(actionIndex++);
Assert.assertNotNull(screenshotAction.getBrowser());
Assert.assertEquals(screenshotAction.getName(), "selenium:screenshot");
Assert.assertEquals(screenshotAction.getOutputDir(), "/tmp/storage");

NavigateAction navigateAction = (NavigateAction) result.getTestAction(actionIndex++);
Assert.assertNull(navigateAction.getBrowser());
Assert.assertEquals(navigateAction.getName(), "selenium:navigate");
Assert.assertEquals(navigateAction.getPage(), "back");

OpenWindowAction openWindowAction = (OpenWindowAction) result.getTestAction(actionIndex++);
Assert.assertNull(openWindowAction.getBrowser());
Assert.assertEquals(openWindowAction.getName(), "selenium:open-window");
Assert.assertEquals(openWindowAction.getWindowName(), "newWindow");

SwitchWindowAction switchWindowAction = (SwitchWindowAction) result.getTestAction(actionIndex++);
Assert.assertNull(switchWindowAction.getBrowser());
Assert.assertEquals(switchWindowAction.getName(), "selenium:switch-window");
Assert.assertEquals(switchWindowAction.getWindowName(), "switchWindow");

CloseWindowAction closeWindowAction = (CloseWindowAction) result.getTestAction(actionIndex++);
Assert.assertNull(closeWindowAction.getBrowser());
Assert.assertEquals(closeWindowAction.getName(), "selenium:close-window");
Assert.assertEquals(closeWindowAction.getWindowName(), "closeWindow");

StoreFileAction storeFileAction = (StoreFileAction) result.getTestAction(actionIndex++);
Assert.assertNull(storeFileAction.getBrowser());
Assert.assertEquals(storeFileAction.getName(), "selenium:store-file");
Assert.assertEquals(storeFileAction.getFilePath(), "classpath:download/file.txt");

GetStoredFileAction getStoredFileAction = (GetStoredFileAction) result.getTestAction(actionIndex++);
Assert.assertNull(getStoredFileAction.getBrowser());
Assert.assertEquals(getStoredFileAction.getName(), "selenium:get-stored-file");
Assert.assertEquals(getStoredFileAction.getFileName(), "file.txt");

ClearBrowserCacheAction clearCacheAction = (ClearBrowserCacheAction) result.getTestAction(actionIndex++);
Assert.assertNull(clearCacheAction.getBrowser());
Assert.assertEquals(clearCacheAction.getName(), "selenium:clear-cache");

StopBrowserAction stopAction = (StopBrowserAction) result.getTestAction(actionIndex++);
Assert.assertNotNull(stopAction.getBrowser());
Assert.assertEquals(stopAction.getName(), "selenium:stop");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* Copyright 2022 the original author or authors.
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.citrusframework.selenium.groovy

import org.openqa.selenium.By

import static org.citrusframework.selenium.actions.SeleniumActionBuilder.selenium

name "SeleniumTest"
author "Christoph"
status "FINAL"
description "Sample test in Groovy"

actions {
$(selenium()
.browser(seleniumBrowser)
.start()
)

$(selenium()
.alert()
.accept()
)

$(selenium()
.alert()
.dismiss()
.text("This is a warning message!")
)

$(selenium()
.find()
.element(By.className("clickable"))
.tagName("button")
.text("Ok")
.displayed(true)
.enabled(true)
.attribute("type", "submit")
.style("color", "#000000")
)

$(selenium()
.page(userForm)
.action("setUserName")
.argument('${username}')
)

$(selenium()
.page(org.citrusframework.selenium.pages.UserFormPage.class)
.action("validate")
.validator(pageValidator)
)

$(selenium()
.click()
.element(By.id("edit-link"))
)

$(selenium()
.hover()
.element(By.id("edit-link"))
)

$(selenium()
.setInput()
.value("new-value")
.element(By.tagName("input"))
)

$(selenium()
.checkInput()
.checked(true)
.element(By.xpath("//input[@type: 'checkbox']"))
)

$(selenium()
.select()
.option("male")
.element(By.name("gender"))
)

$(selenium()
.select()
.element(By.id("title"))
.options("Mr.", "Dr.")
)

$(selenium()
.waitUntil()
.hidden()
.element(By.id("dialog"))
)

$(selenium()
.javascript()
.script("alert('This is awesome!')")
.error("Something went wrong")
)

$(selenium()
.browser(seleniumBrowser)
.screenshot()
.outputDir("/tmp/storage")
)

$(selenium()
.navigate()
.page("back")
)

$(selenium()
.open()
.window("newWindow")
)

$(selenium()
.focus()
.window("switchWindow")
)

$(selenium()
.close()
.window( "closeWindow")
)

$(selenium()
.store()
.filePath("classpath:download/file.txt")
)

$(selenium()
.getStored()
.fileName("file.txt")
)

$(selenium()
.clearCache()
)

$(selenium()
.stop()
.browser(seleniumBrowser)
)
}