Skip to content

Commit

Permalink
#68 Add safari web driver and start integration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
christophd committed Jan 2, 2017
1 parent 51dad45 commit 06ccd52
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 1 deletion.
Expand Up @@ -31,6 +31,7 @@
<xs:restriction base="xs:string">
<xs:enumeration value="htmlunit"/>
<xs:enumeration value="firefox"/>
<xs:enumeration value="safari"/>
<xs:enumeration value="chrome"/>
<xs:enumeration value="googlechrome"/>
<xs:enumeration value="internet explorer"/>
Expand Down
Expand Up @@ -31,6 +31,7 @@
<xs:restriction base="xs:string">
<xs:enumeration value="htmlunit"/>
<xs:enumeration value="firefox"/>
<xs:enumeration value="safari"/>
<xs:enumeration value="chrome"/>
<xs:enumeration value="googlechrome"/>
<xs:enumeration value="internet explorer"/>
Expand Down
7 changes: 7 additions & 0 deletions modules/citrus-selenium/pom.xml
Expand Up @@ -30,5 +30,12 @@
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
</dependency>

<dependency>
<groupId>com.consol.citrus</groupId>
<artifactId>citrus-http</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Expand Up @@ -18,6 +18,7 @@

import com.consol.citrus.context.TestContext;
import com.consol.citrus.selenium.endpoint.SeleniumBrowser;
import org.springframework.util.StringUtils;

/**
* @author Tamer Erdogan, Christoph Deppisch
Expand Down Expand Up @@ -47,6 +48,12 @@ protected void execute(SeleniumBrowser browser, TestContext context) {
log.info("Opening browser of type {}", browser.getEndpointConfiguration().getBrowserType());
browser.start();

if (StringUtils.hasText(getBrowser().getEndpointConfiguration().getStartPageUrl())) {
NavigateAction openStartPage = new NavigateAction();
openStartPage.setPage(getBrowser().getEndpointConfiguration().getStartPageUrl());
openStartPage.execute(browser, context);
}

context.setVariable("selenium_browser", browser.getName());
}

Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.*;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.openqa.selenium.support.events.WebDriverEventListener;
import org.slf4j.Logger;
Expand Down Expand Up @@ -173,6 +174,8 @@ private WebDriver createLocalWebDriver(String browserType) {
return new FirefoxDriver(defaults);
case BrowserType.IE:
return new InternetExplorerDriver();
case BrowserType.SAFARI:
return new SafariDriver();
case BrowserType.CHROME:
return new ChromeDriver();
case BrowserType.GOOGLECHROME:
Expand Down
@@ -0,0 +1,33 @@
/*
* Copyright 2006-2017 the original author or authors.
*
* Licensed 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 com.consol.citrus.selenium.integration;

import com.consol.citrus.annotations.CitrusXmlTest;
import com.consol.citrus.testng.AbstractTestNGCitrusTest;
import org.testng.annotations.Test;

/**
* @author Christoph Deppisch
* @since 2.7
*/
public class SeleniumIT extends AbstractTestNGCitrusTest {

@Test
@CitrusXmlTest
public void SeleniumIT() {
}
}
16 changes: 15 additions & 1 deletion modules/citrus-selenium/src/test/resources/citrus-context.xml
Expand Up @@ -3,12 +3,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:citrus="http://www.citrusframework.org/schema/config"
xmlns:citrus-selenium="http://www.citrusframework.org/schema/selenium/config"
xmlns:citrus-http="http://www.citrusframework.org/schema/http/config"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.citrusframework.org/schema/config http://www.citrusframework.org/schema/config/citrus-config.xsd
http://www.citrusframework.org/schema/selenium/config http://www.citrusframework.org/schema/selenium/config/citrus-selenium-config.xsd">
http://www.citrusframework.org/schema/selenium/config http://www.citrusframework.org/schema/selenium/config/citrus-selenium-config.xsd
http://www.citrusframework.org/schema/http/config http://www.citrusframework.org/schema/http/config/citrus-http-config.xsd">

<context:property-placeholder location="classpath:citrus.properties"
ignore-unresolvable="true"/>
Expand All @@ -21,4 +23,16 @@
<citrus-selenium:browser id="webBrowser"
type="htmlunit"/>

<citrus-http:server id="webServer"
port="19090"
auto-start="true"
endpoint-adapter="indexPageAdapter"/>

<citrus:static-response-adapter id="indexPageAdapter">
<citrus:resource file="templates/index.html"/>
<citrus:header>
<citrus:element name="Content-Type" value="text/html"/>
</citrus:header>
</citrus:static-response-adapter>

</beans>
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<spring:beans xmlns="http://www.citrusframework.org/schema/testcase"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:selenium="http://www.citrusframework.org/schema/selenium/testcase"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.citrusframework.org/schema/selenium/testcase
http://www.citrusframework.org/schema/selenium/testcase/citrus-selenium-testcase.xsd
http://www.citrusframework.org/schema/testcase
http://www.citrusframework.org/schema/testcase/citrus-testcase.xsd">

<testcase name="SeleniumIT">
<meta-info>
<author>Christoph Deppisch</author>
<creationdate>2017-01-02</creationdate>
<status>FINAL</status>
<last-updated-by>Christoph Deppisch</last-updated-by>
<last-updated-on>2017-01-02T00:00:00</last-updated-on>
</meta-info>

<description>Test selenium command execution with browser client.</description>

<actions>
<echo>
<message>Validate Selenium browser commands</message>
</echo>

<selenium:start browser="webBrowser"/>

<selenium:navigate page="http://localhost:19090"/>

<selenium:find>
<selenium:element tag-name="h1"/>
</selenium:find>

<selenium:click>
<selenium:element id="open-alert"/>
</selenium:click>

<sleep milliseconds="1000"/>

<selenium:alert action="accept"/>

<selenium:click>
<selenium:element link-text="Say Hello!"/>
</selenium:click>

<sleep milliseconds="500"/>

<selenium:alert action="accept"/>

<selenium:stop browser="webBrowser"/>

</actions>

</testcase>
</spring:beans>
@@ -0,0 +1,8 @@
<html>
<body>
<h1>Welcome!</h1>

<p><button id="open-alert" onclick="alert('Hello');">Say Hello!</button></p>
<p><a href="#" onclick="alert('Hello');">Say Hello!</a></p>
</body>
</html>

0 comments on commit 06ccd52

Please sign in to comment.