Skip to content

Commit

Permalink
Refactor codegen and add a cli-only version of it
Browse files Browse the repository at this point in the history
- Existing 'codegen' directory becomes codegen cli
- New 'codegen-maven' directory depends on cli variant and adds maven
  plugin specifics
- Refactor several classes to minimize code duplication
- Add a few tests
- Bump maven-plugin dependencies in parent pom
- Unrelated typo correction in 'client' AbstractElement.java
- Add README.md for codegen-cli
  • Loading branch information
Doug Simmons committed Jun 23, 2017
1 parent 2b3629a commit 5875843
Show file tree
Hide file tree
Showing 56 changed files with 2,656 additions and 1,255 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------------------------------------------------*\
| Copyright (C) 2014-2016 PayPal |
| Copyright (C) 2014-2017 PayPal |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| with the License. |
Expand Down Expand Up @@ -95,7 +95,7 @@ protected ElementEventListener getDispatcher() {

/**
* Instance method used to call static class method locateElement.
*
*
* @return the web element found by locator
*/
public RemoteWebElement getElement() {
Expand All @@ -117,7 +117,7 @@ public RemoteWebElement getElement() {

/**
* Instance method used to call static class method locateElements.
*
*
* @return the list of web elements found by locator
*/
public List<WebElement> getElements() {
Expand All @@ -137,7 +137,7 @@ public List<WebElement> getElements() {

/**
* A utility method to provide additional information to the user when a NoSuchElementException is thrown.
*
*
* @param cause
* The associated cause for the exception.
*/
Expand Down Expand Up @@ -181,7 +181,7 @@ private void addInfoForNoSuchElementException(NoSuchElementException cause) {

/**
* Constructs an AbstractElement with locator.
*
*
* @param locator
*/
public AbstractElement(String locator) {
Expand All @@ -190,7 +190,7 @@ public AbstractElement(String locator) {

/**
* Constructs an AbstractElement with locator and parent.
*
*
* @param parent
* A {@link ParentTraits} object that represents the parent element for this element.
* @param locator
Expand All @@ -203,7 +203,7 @@ public AbstractElement(ParentTraits parent, String locator) {

/**
* Constructs an AbstractElement with locator and controlName.
*
*
* @param locator
* the element locator
* @param controlName
Expand All @@ -215,7 +215,7 @@ public AbstractElement(String locator, String controlName) {

/**
* Constructs an AbstractElement with locator, parent, and controlName.
*
*
* @param locator
* A String that represents the means to locate this element (could be id/name/xpath/css locator).
* @param controlName
Expand All @@ -231,7 +231,7 @@ public AbstractElement(String locator, String controlName, ParentTraits parent)

/**
* Retrieves the locator (id/name/xpath/css locator) for the current {@link AbstractElement} element.
*
*
* @return The value of locator.
*/
public String getLocator() {
Expand All @@ -240,7 +240,7 @@ public String getLocator() {

/**
* Retrieves the control name for the current {@link AbstractElement} element.
*
*
* @return The value of controlName.
*/
public String getControlName() {
Expand All @@ -249,7 +249,7 @@ public String getControlName() {

/**
* Retrieves the parent element for the current {@link AbstractElement} element.
*
*
* @return A {@link ParentTraits} that represents the parent of the current {@link AbstractElement} element.
*/
public ParentTraits getParent() {
Expand All @@ -259,7 +259,7 @@ public ParentTraits getParent() {
/**
* Finds element on the page and returns the visible (i.e. not hidden by CSS) innerText of this element, including
* sub-elements, without any leading or trailing whitespace.
*
*
* @return The innerText of this element.
*/
public String getText() {
Expand All @@ -270,7 +270,7 @@ public String getText() {
* Checks if element is present in the html dom. An element that is present in the html dom does not mean it is
* visible. To check if element is visible, use {@link #getElement()} to get {@link WebElement} and then invoke
* {@link WebElement#isDisplayed()}.
*
*
* @return True if element is present, false otherwise.
*/
public boolean isElementPresent() {
Expand All @@ -290,7 +290,7 @@ public boolean isElementPresent() {
/**
* Is this element displayed or not? This method avoids the problem of having to parse an element's "style"
* attribute.
*
*
* @return Whether or not the element is displayed
*/
public boolean isVisible() {
Expand All @@ -300,7 +300,7 @@ public boolean isVisible() {
/**
* Is the element currently enabled or not? This will generally return true for everything but disabled input
* elements.
*
*
* @return True if element is enabled, false otherwise.
*/
public boolean isEnabled() {
Expand All @@ -318,8 +318,8 @@ public boolean isEnabled() {
* ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open, paused, pubdate,
* readonly, required, reversed, scoped, seamless, seeking, selected, spellcheck, truespeed, willvalidate. Finally,
* the following commonly mis-capitalized attribute/property names are evaluated as expected: class, readonly
*
*
*
*
* @param attributeName
* the attribute name to get current value
* @return The attribute's current value or null if the value is not set.
Expand All @@ -331,7 +331,7 @@ public String getAttribute(String attributeName) {
/**
* Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter). For
* checkbox/radio elements, the value will be "on" or "off" depending on whether the element is checked or not.
*
*
* @return the element value, or "on/off" for checkbox/radio elements
*/
public String getValue() {
Expand All @@ -340,7 +340,7 @@ public String getValue() {

/**
* Gets value from property map {@link #propMap}.
*
*
* @param key
* the key to retrieve a value from the property map
* @return the value to which the specified key is mapped, or null if this map contains no mapping for the key
Expand All @@ -351,7 +351,7 @@ public String getProperty(String key) {

/**
* Sets value in property map {@link #propMap}.
*
*
* @param key
* @param value
*/
Expand Down Expand Up @@ -393,7 +393,7 @@ protected void processScreenShot() {
try {
title = Grid.driver().getTitle();
} catch (WebDriverException thrown) { // NOSONAR
logger.log(Level.FINER, "An exception occured while getting page title", thrown);
logger.log(Level.FINER, "An exception occurred while getting page title", thrown);
}
boolean logPages = Boolean.parseBoolean(Config.getConfigProperty(ConfigProperty.LOG_PAGES));
if (Boolean.parseBoolean(Config.getConfigProperty(ConfigProperty.AUTO_SCREEN_SHOT))) {
Expand Down Expand Up @@ -458,15 +458,15 @@ public void click() {

/**
* Basic click event on the Element. Doesn't wait for anything to load.
*
*
*/
public void clickonly() {
click(new Object[] {});
}

/**
* The click function and wait for expected {@link Object} items to load.
*
*
* @param expected
* parameters in the form of an element locator {@link String}, a {@link WebPage}, an
* {@link AbstractElement}, or an {@link ExpectedCondition}
Expand Down Expand Up @@ -519,20 +519,20 @@ public void click(Object... expected) {

/**
* The click function and wait based on the ExpectedCondition.
*
*
* @param expectedCondition
* ExpectedCondition<?> instance to be passed.
*
*
* @return The return value of
* {@link org.openqa.selenium.support.ui.FluentWait#until(com.google.common.base.Function)} if the function
* returned something different from null or false before the timeout expired.<br>
*
*
* <pre>
* Grid.driver().get(&quot;https://www.paypal.com&quot;);
* TextField userName = new TextField(&quot;login_email&quot;);
* TextField password = new TextField(&quot;login_password&quot;);
* Button btn = new Button(&quot;submit.x&quot;);
*
*
* userName.type(&quot;[email protected]&quot;);
* password.type(&quot;123Abcde&quot;);
* btn.clickAndExpect(ExpectedConditions.titleIs(&quot;MyAccount - PayPal&quot;));
Expand Down Expand Up @@ -560,7 +560,7 @@ public Object clickAndExpect(ExpectedCondition<?> expectedCondition) {
* Click function that will wait for one of the ExpectedConditions to match.
* {@link org.openqa.selenium.TimeoutException} exception will be thrown if no conditions are matched within the
* allowed time {@link ConfigProperty#EXECUTION_TIMEOUT}
*
*
* @param conditions
* {@link List}&lt;{@link ExpectedCondition}&lt;?&gt;&gt; of supplied conditions passed.
* @return first {@link org.openqa.selenium.support.ui.ExpectedCondition} that was matched
Expand Down Expand Up @@ -630,7 +630,7 @@ public ExpectedCondition<?> apply(WebDriver webDriver) {

/**
* The click function and wait for one of the expected {@link Object} items to load.
*
*
* @param expected
* parameters in the form of an element locator {@link String}, a {@link WebPage}, or an
* {@link AbstractElement}
Expand Down Expand Up @@ -710,7 +710,7 @@ public Object apply(WebDriver webDriver) {

/**
* Moves the mouse pointer to the middle of the element. And waits for the expected elements to be visible.
*
*
* @param expected
* parameters in the form of an element locator {@link String} or an {@link AbstractElement}
*/
Expand Down
128 changes: 128 additions & 0 deletions codegen-maven/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>com.paypal.selion</groupId>
<artifactId>SeLion-Parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>SeLion-Code-Generator</artifactId>
<packaging>maven-plugin</packaging>
<name>SeLion Code Generator Maven Mojo</name>

<build>
<resources>
<resource>
<directory>..</directory>
<includes>
<include>LICENSE</include>
</includes>
<targetPath>META-INF/</targetPath>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.paypal.selion</groupId>
<artifactId>SeLion-Project-BOM</artifactId>
<version>${project.bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.paypal.selion</groupId>
<artifactId>SeLion-Code-Generator-CLI</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.5</version>
<exclusions>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
<!-- version 21.0 (in SeLion BOM) requires java 8 - maven-core 3.3.9 is not compatible -->
<!-- since this code generation step runs as a project build step, we should be okay -->
<!-- specifying a different guava version than SeLion will depend on during runtime -->
<version>20.0</version>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.3.9</version>
<exclusions>
<!-- excluded due to enforcer version conflict -->
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-classworlds</artifactId>
</exclusion>
<!-- excluded due to enforcer version conflict -->
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</exclusion>
<!-- excluded due to enforcer version conflict -->
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
</exclusion>
<!-- excluded due to enforcer version conflict -->
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
<version>1.6</version>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-classworlds</artifactId>
<version>2.5.2</version>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.20</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit 5875843

Please sign in to comment.