-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from alfa-laboratory/add_appium_server_runner
Add appium server runner
- Loading branch information
Showing
6 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 14 additions & 1 deletion
15
src/main/java/ru/colibri/ui/settings/general/GeneralConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/ru/colibri/ui/settings/server/AbstractServerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
src/main/java/ru/colibri/ui/settings/server/AppiumServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
52
src/test/java/ru/colibri/ui/settings/server/AppiumServerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
|
||
} |