Skip to content

Commit

Permalink
Add brower build targets to travis
Browse files Browse the repository at this point in the history
- Add additional build targets for travis CI to also run our
  chrome and firefox suites locally.
- Also moved the "deploy" step to phantom target.
- Reduced the number of threads in some test suites
- Added a custom test capabilityprovider for setting browser options
- Need to add "--no-sandbox" for chrome execution to work around
  chrome on OpenVZ.
- Also add firefox in travis CI using Firefox-suite
- Other minor test updates
- Keep all temporary test files in target folder
  • Loading branch information
Sherif Ebady authored and Doug Simmons committed Nov 2, 2016
1 parent f6d29fb commit 78af14d
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ xcuserdata
*.hmap
*.ipa

Carthage/Build
Carthage/Build
40 changes: 35 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ language: java
sudo: false
jdk:
- oraclejdk8
script:
- sh -e utilities/travis-run-ci-tests.sh
after_success:
- sh -e utilities/travis-push-javadoc-to-gh-pages.sh
- sh -e utilities/travis-deploy-to-sonatype.sh
addons:
sauce_connect: true
cache:
directories:
- $HOME/.m2
notifications:
irc:
channels:
Expand All @@ -22,3 +20,35 @@ notifications:
on_success: change
on_failure: always
on_start: never
env:
global:
- DISPLAY=:99.0
matrix:
- TARGET=phantom
- TARGET=chrome
- TARGET=firefox
matrix:
allow_failures:
- env: TARGET=chrome
- env: TARGET=firefox
fast_finish: true
before_script:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sh -e /etc/init.d/xvfb start; sleep 3; fi
- echo "MAVEN_OPTS='-Xmx1g -Xms256m'" > ~/.mavenrc
script:
- |
if [[ $TRAVIS_OS_NAME == 'linux' ]] && [[ $TARGET == *"phantom"* ]]; then
sh -e utilities/travis-run-ci-tests.sh
if [[ $? == 0 ]]; then
sh -e utilities/travis-push-javadoc-to-gh-pages.sh
sh -e utilities/travis-deploy-to-sonatype.sh
fi
fi
- |
if [[ $TRAVIS_OS_NAME == 'linux' ]] && [[ $TARGET == *"chrome"* ]]; then
sh -e utilities/travis-run-chrome-tests.sh
fi
- |
if [[ $TRAVIS_OS_NAME == 'linux' ]] && [[ $TARGET == *"firefox"* ]]; then
sh -e utilities/travis-run-firefox-tests.sh
fi
45 changes: 45 additions & 0 deletions client/src/test/java/com/paypal/selion/TestCapabilityBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.paypal.selion;

import com.paypal.selion.configuration.Config;
import com.paypal.selion.configuration.Config.ConfigProperty;
import com.paypal.selion.internal.platform.grid.BrowserFlavors;
import com.paypal.selion.internal.platform.grid.WebTestSession;
import com.paypal.selion.platform.grid.Grid;
import com.paypal.selion.platform.grid.browsercapabilities.DefaultCapabilitiesBuilder;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.HashMap;
import java.util.Map;

/**
* A custom capabilitiesBuilder used during test executions to establish custom browser paths and options.
*/
public class TestCapabilityBuilder extends DefaultCapabilitiesBuilder {

@Override
public DesiredCapabilities getCapabilities(DesiredCapabilities capabilities) {
String browserPath = System.getProperty("BROWSER_PATH");
WebTestSession session = Grid.getWebTestSession();
if (StringUtils.isEmpty(browserPath) || session == null) {
return capabilities;
}

String browser = session.getBrowser();
if (browser.equals(BrowserFlavors.CHROME.getBrowser())) {
ChromeOptions options = new ChromeOptions();
options.setBinary(browserPath);
// To run chrome on virtualized openVZ environments
options.addArguments("--no-sandbox");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
} else if (browser.equals(BrowserFlavors.FIREFOX.getBrowser())) {
Map<String, String> firefoxOptions = new HashMap<>();
firefoxOptions.put("binary", browserPath);
String key = Config.getBoolConfigProperty(ConfigProperty.SELENIUM_USE_GECKODRIVER) ?
"moz:firefoxOptions" : "firefox_binary";
capabilities.setCapability(key, firefoxOptions);
}
return capabilities;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public void testWithSafari() {
// And now use this to visit Google
driver.get("http://www.google.com");
SeLionReporter.log("Page loaded", true, true);
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Find the text input element by its id
WebElement element = driver.findElement(By.id("lst-ib"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testMultiTap() throws Exception {
multiTapButton.doubleTap();
Assert.assertEquals(tapPage.getMultiTapTextField().getValue(), "Tap Count: 2");
} else {
Assert.fail("paltform " + tapPage.getPlatform().name() + " does not support double tap.");
Assert.fail("platform " + tapPage.getPlatform().name() + " does not support double tap.");
}

}
Expand Down
4 changes: 2 additions & 2 deletions client/src/test/resources/suites/Chrome-Suite.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="10" verbose="1" name="Chrome Unit Test Suite" skipfailedinvocationcounts="false" junit="false"
parallel="methods" data-provider-thread-count="50" annotations="JDK">
<suite thread-count="5" verbose="1" name="Chrome Unit Test Suite" skipfailedinvocationcounts="false" junit="false"
parallel="methods" data-provider-thread-count="10" annotations="JDK">

<parameter name="browser" value="*chrome" />

Expand Down
4 changes: 2 additions & 2 deletions client/src/test/resources/suites/Firefox-Suite.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="10" verbose="1" name="Firefox Unit Test Suite" skipfailedinvocationcounts="false" junit="false"
parallel="methods" data-provider-thread-count="50" annotations="JDK">
<suite thread-count="5" verbose="1" name="Firefox Unit Test Suite" skipfailedinvocationcounts="false" junit="false"
parallel="methods" data-provider-thread-count="10" annotations="JDK">

<parameter name="browser" value="*firefox" />

Expand Down
35 changes: 35 additions & 0 deletions utilities/travis-run-chrome-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -e

#############################################################
# This script updates travis CI with chromedriver and starts
# the selion chrome suite locally
#############################################################
if [ -n "${SAUCE_USERNAME}" ]; then
echo { \"sauceUserName\": \"${SAUCE_USERNAME}\", \"sauceApiKey\": \"${SAUCE_ACCESS_KEY}\", \"tunnel-identifier\": \"__string__${TRAVIS_JOB_NUMBER}\", \"build\": \"${TRAVIS_BUILD_NUMBER}\", \"idle-timeout\": 120, \"tags\": [\"commit ${TRAVIS_COMMIT}\", \"branch ${TRAVIS_BRANCH}\", \"pull request ${TRAVIS_PULL_REQUEST}\"] } > client/src/test/resources/sauceConfig.json
fi

mkdir -p target
cd target
if [ ! -f "./google-chrome" ]; then
export CHROME_REVISION=`curl -s http://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/LAST_CHANGE`
curl -L -O "http://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/${CHROME_REVISION}/chrome-linux.zip"
unzip -o chrome-linux.zip
ln -sf $PWD/chrome-linux/chrome-wrapper google-chrome
fi

./google-chrome -version

if [ ! -f "./chromedriver" ]; then
export CHROMEDRIVER_VERSION=2.24
curl -L -O "http://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip"
unzip -o chromedriver_linux64.zip && chmod +x chromedriver
fi
cd ..

export PATH=$PWD/target:$PATH
mvn test -pl client -DsuiteXmlFile=Chrome-Suite.xml \
-DSELION_SELENIUM_RUN_LOCALLY=true \
-DSELION_SELENIUM_CHROMEDRIVER_PATH=$PWD/target/chromedriver \
-DSELION_SELENIUM_CUSTOM_CAPABILITIES_PROVIDER=com.paypal.selion.TestCapabilityBuilder \
-DBROWSER_PATH=$PWD/target/google-chrome -B -V
43 changes: 43 additions & 0 deletions utilities/travis-run-firefox-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
set -e

#############################################################
# This script updates travis with firefox and
# geckodriver and starts the selion firefox suites locally
#############################################################

if [ -n "${SAUCE_USERNAME}" ]; then
echo { \"sauceUserName\": \"${SAUCE_USERNAME}\", \"sauceApiKey\": \"${SAUCE_ACCESS_KEY}\", \"tunnel-identifier\": \"__string__${TRAVIS_JOB_NUMBER}\", \"build\": \"${TRAVIS_BUILD_NUMBER}\", \"idle-timeout\": 120, \"tags\": [\"commit ${TRAVIS_COMMIT}\", \"branch ${TRAVIS_BRANCH}\", \"pull request ${TRAVIS_PULL_REQUEST}\"] } > client/src/test/resources/sauceConfig.json
fi

# Remove any existing firefox data
if [[ $TRAVIS == "true" ]]
then
rm -fr ~/.mozilla
fi

mkdir -p target
cd target
if [ ! -f "./firefox/firefox" ]
then
export FIREFOX_VERSION=49.0.1
export FIREFOX_URL=http://download.cdn.mozilla.net/pub/firefox/releases/${FIREFOX_VERSION}/linux-x86_64/en-US/firefox-${FIREFOX_VERSION}.tar.bz2
wget -O firefox-${FIREFOX_VERSION}.tar.bz2 ${FIREFOX_URL}
# and install downloaded firefox
tar -xjf firefox-${FIREFOX_VERSION}.tar.bz2
fi

if [ ! -f "./geckodriver" ]
then
export GECKODRIVER_VERSION=v0.11.1
curl -L -o geckodriver.tar.gz https://github.com/mozilla/geckodriver/releases/download/${GECKODRIVER_VERSION}/geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz
gunzip -c geckodriver.tar.gz | tar xopf -
chmod +x geckodriver
fi
cd ..

export PATH="$PWD/target/firefox:$PATH"
mvn test -pl client -B -V -DsuiteXmlFile=Firefox-Suite.xml -DSELION_SELENIUM_RUN_LOCALLY=true \
-DSELION_SELENIUM_USE_GECKODRIVER=true -DSELION_SELENIUM_GECKODRIVER_PATH=$PWD/target/geckodriver \
-DSELION_SELENIUM_CUSTOM_CAPABILITIES_PROVIDER=com.paypal.selion.TestCapabilityBuilder \
-DBROWSER_PATH=$PWD/target/firefox/firefox

0 comments on commit 78af14d

Please sign in to comment.