Skip to content

Commit

Permalink
Merge pull request #23 from alfa-laboratory/add_appium_server_runner
Browse files Browse the repository at this point in the history
Add appium server runner
  • Loading branch information
JasperJhons authored Oct 30, 2017
2 parents d91d743 + 13face9 commit 3d02eb5
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ jdk:
- oraclejdk8
install: true
before_install:
- npm install -g appium
- test $TRAVIS_PULL_REQUEST = false && openssl aes-256-cbc -K $encrypted_45a1e02b23ba_key
-iv $encrypted_45a1e02b23ba_iv -in gradle.properties.enc -out gradle.properties
-d || true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ public class ColibriStartFlags {
public static final String USER = "user";
public static final String TEST_TYPE = "testType";
public static final String BUILD_VERSION = "buildVersion";
public static final String PORT = "port";
}
15 changes: 14 additions & 1 deletion src/main/java/ru/colibri/ui/settings/general/GeneralConfig.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package ru.colibri.ui.settings.general;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import ru.colibri.ui.settings.server.AppiumServer;

@Configuration
@ComponentScan(basePackages = {"ru.colibri.ui.core", "ru.colibri.ui.settings.general", "ru.colibri.ui.steps.general"})
@ComponentScan(basePackages = {"ru.colibri.ui.core", "ru.colibri.ui.settings.general", "ru.colibri.ui.steps.general", "ru.colibri.ui.settings.server"})
public class GeneralConfig {

@Autowired
private AppiumServer server;

@Bean
public AppiumServer getAppiumServer() {
AppiumServer server = new AppiumServer();
server.startServer();
return server;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.colibri.ui.settings.server;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public abstract class AbstractServerConfig {

private String port;
private String host;

}
36 changes: 36 additions & 0 deletions src/main/java/ru/colibri/ui/settings/server/AppiumServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ru.colibri.ui.settings.server;

import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.GeneralServerFlag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AppiumServer {

@Autowired
private AbstractServerConfig config;


private AppiumDriverLocalService service;


public void startServer() {

AppiumServiceBuilder builder = new AppiumServiceBuilder();
builder.withIPAddress(config.getHost());
builder.usingPort(Integer.parseInt(config.getPort()));
builder.withArgument(GeneralServerFlag.SESSION_OVERRIDE);
builder.withArgument(GeneralServerFlag.LOG_LEVEL, "error");

service = AppiumDriverLocalService.buildService(builder);
service.start();
}

public void stopServer() {
service.stop();
}


}
52 changes: 52 additions & 0 deletions src/test/java/ru/colibri/ui/settings/server/AppiumServerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package ru.colibri.ui.settings.server;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;

import static org.mockito.Mockito.when;


@RunWith(MockitoJUnitRunner.class)
public class AppiumServerTest {

@InjectMocks
AppiumServer server;

@Mock
AbstractServerConfig config;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}

@Test
public void startAndStopServer() throws Exception {
when(config.getHost()).thenReturn("0.0.0.0");
when(config.getPort()).thenReturn("4723");
server.startServer();
server.stopServer();
}

@Test(expected = IllegalArgumentException.class)
public void startServerWithWrongHost() throws Exception {
when(config.getHost()).thenReturn("1.2.3.4.5.6.7");
when(config.getPort()).thenReturn("4723");
server.startServer();

}

@Test(expected = IllegalArgumentException.class)
public void startServerWithWrongPort() throws Exception {
when(config.getHost()).thenReturn("0.0.0.0");
when(config.getPort()).thenReturn("-4723");
server.startServer();

}

}

0 comments on commit 3d02eb5

Please sign in to comment.