-
-
Notifications
You must be signed in to change notification settings - Fork 765
Tests of local appium DriverService were re-designed. #728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
| public class ServerBuilderTest { | ||
|
|
||
| private static String pathToAppiumNodeInProperties; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably, we can mark properties, which are not going to be changed, as final
| testIP = null; | ||
| } | ||
| } | ||
| if (testIP != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume having this in a separate private method would save us several lines of code (break -> return) and will improve readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the returned result can be of type Optional
| } | ||
|
|
||
| ofNullable(file).ifPresent(fileArg -> { | ||
| if (file.exists()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file or fileArg?
| } | ||
|
|
||
| @Test public void checkAbilityToUseNodeDefinedExplicitly() { | ||
| File node = new File("src/test/java/io/appium/java_client/service/local/appium.js"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the magic string can be moved to constants
| } | ||
|
|
||
| @Test public void checkAbilityToStartServiceUsingCapabilities() throws Exception { | ||
| File appDir = new File("src/test/java/io/appium/java_client"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are many common root paths. The common part can be represented as a constant, so then one can use new File(parent, basename) constructor, where parent is a constant
| service = buildDefaultService(); | ||
| service.addOutPutStream(stream); | ||
| service.start(); | ||
| assertTrue(file.length() > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> assertThat(file.length(), greaterThan(0L))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a bit longer, but produces better error message in comparison to the generic True assertion
| new AppiumServiceBuilder().usingAnyFreePort().build(), | ||
| new AppiumServiceBuilder().usingAnyFreePort().build(), | ||
| new AppiumServiceBuilder().usingAnyFreePort().build()); | ||
| services.parallelStream().forEach(AppiumDriverLocalService::start); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
| service = new AppiumServiceBuilder().withLogFile(file).build(); | ||
| service.start(); | ||
| assertTrue(file.exists()); | ||
| assertTrue(file.length() > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
|
Shall we add a description somewhere about src/test/java/io/appium/java_client/service/local/appium.js is just a stub? |
mykola-mokhnach
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
|
@mykola-mokhnach @SrinivasanTarget |
| if (validator.isValid(result)) { | ||
| return result; | ||
| } | ||
| return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return validator.isValid(result) ? result : null;
| if (!inetAddress.isLoopbackAddress()) { | ||
| InetAddressValidator validator = InetAddressValidator.getInstance(); | ||
|
|
||
| testIP = ofNullable(testIP).orElseGet(() -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't work as expected, because the iteration does not stop here even if testIP set. Please extract the loop into a separate method private static Optional<String> getTestIP(), so then beforeClass's body should look like testIP = getTestIP().orElseThrow(() -> new IllegalStateException("Cannot initialize the IP address for tests"))
| */ | ||
| private static final String PATH_TO_APPIUM_NODE_IN_PROPERTIES = getProperty(APPIUM_PATH); | ||
|
|
||
| private static final String ROOT_TEST_PATH = "src/test/java/io/appium/java_client/"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing slash is not needed if path concatenation is done in File constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, will these tests work properly in Windows if one hardcodes path separators?
| /** | ||
| * This is the path to the stub appium.js file | ||
| */ | ||
| private static final String PATH_T0_TEST_APPIUM_JS = ROOT_TEST_PATH + "service/local/appium.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be more handy to keep it as File object:
TEST_APPIUM_JS = Path.get(ROOT_TEST_PATH).resolve("service").resolve("local").resolve("appium.js").toFile()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TikhomirovSergey Why don't we name stub as main.js in sync with appium server's main.js?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SrinivasanTarget
Because it searches for appium.js when it tries to launch the node locally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TikhomirovSergey with the latest appium its main.js as @SrinivasanTarget mentioned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SrinivasanTarget @saikrishna321 Oops! My fault. yes. Guys you are right :)
| }); | ||
|
|
||
| System.clearProperty(APPIUM_PATH); | ||
| ofNullable(PATH_TO_APPIUM_NODE_IN_PROPERTIES).ifPresent(s -> setProperty(APPIUM_PATH, s)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the constant cannot be null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mykola-mokhnach It may be null when the property was not defined
|
|
||
| @Test public void checkAbilityToStartServiceUsingCapabilitiesAndFlags() throws Exception { | ||
| File app = new File(ROOT_TEST_PATH, "ApiDemos-debug.apk"); | ||
| File chrome = new File(new File(ROOT_TEST_PATH, "pagefactory_tests"), "chromedriver.exe"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Path.resolve method to construct longer paths
|
Ok. Will improve it ASAP |
|
@mykola-mokhnach @SrinivasanTarget |
| private File testLogFile; | ||
| private OutputStream stream; | ||
|
|
||
| private static String getLocalIP(NetworkInterface intf) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add Nullable annotation
| InetAddressValidator validator = InetAddressValidator.getInstance(); | ||
| calculated = inetAddress.getHostAddress().toString(); | ||
| if (validator.isValid(calculated)) { | ||
| result = calculated; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return calculated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will try it but codecy is sensetive to things like that
| } | ||
| } | ||
| } | ||
| return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return null, result variable is not needed.
| String result = null; | ||
| for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr | ||
| .hasMoreElements(); ) { | ||
| String calculated; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the point to define calculated before if condition?
| public void tearDown() throws Exception { | ||
| ofNullable(service).ifPresent(AppiumDriverLocalService::stop); | ||
|
|
||
| if (stream != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ofNullable(stream).ifPresent(OutputStream::close). Just to be consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It throws the checked IO exception that needs to be handled by catch. So I decided to change nothing there because lambda with the catch clause looks not so cool.
| } | ||
|
|
||
| @Test public void checkAbilityToFindNodeDefinedInProperties() { | ||
| File definedNode = PATH_T0_TEST_MAIN_JS.toFile(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
mykola-mokhnach
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments. Otherwise all good
Change list
Test of the appium-specific DriverService implementation were improved/redesigned.
Types of changes
Details
We are going to improve tests and make them runnable on many environments.
#325 #494