@@ -222,7 +222,7 @@ private static File findCustomNode() {
222222 }
223223
224224 @ Test public void checkAbilityToChangeOutputStream () throws Exception {
225- File file = new File ("target/ test" );
225+ File file = new File ("test" );
226226 file .createNewFile ();
227227 OutputStream stream = new FileOutputStream (file );
228228 AppiumDriverLocalService service = AppiumDriverLocalService .buildDefaultService ();
@@ -243,7 +243,7 @@ private static File findCustomNode() {
243243 }
244244
245245 @ Test public void checkAbilityToChangeOutputStreamAfterTheServiceIsStarted () throws Exception {
246- File file = new File ("target/ test" );
246+ File file = new File ("test" );
247247 file .createNewFile ();
248248 OutputStream stream = new FileOutputStream (file );
249249 AppiumDriverLocalService service = AppiumDriverLocalService .buildDefaultService ();
@@ -295,8 +295,7 @@ private static File findCustomNode() {
295295
296296 @ Test public void checkAbilityToStartServiceWithLogFile () throws Exception {
297297 AppiumDriverLocalService service = null ;
298- File rootLogDir = new File ("target/" );
299- File log = new File (rootLogDir , "Log.txt" );
298+ File log = new File ("Log.txt" );
300299 log .createNewFile ();
301300 try {
302301 service = new AppiumServiceBuilder ().withLogFile (log ).build ();
@@ -312,4 +311,124 @@ private static File findCustomNode() {
312311 }
313312 }
314313 }
314+
315+ @ Test public void checkAbilityToBuildServiceWithPortUsingFlag () throws Exception {
316+ String port = "8996" ;
317+ String expectedUrl = String .format ("http://0.0.0.0:%s/wd/hub" , port );
318+
319+ AppiumDriverLocalService service = null ;
320+
321+ try {
322+ service = new AppiumServiceBuilder ()
323+ .withArgument (() -> "--port" , port )
324+ .build ();
325+ service .start ();
326+ String actualUrl = service .getUrl ().toString ();
327+ assertEquals (expectedUrl , actualUrl );
328+ } finally {
329+ if (service != null ) {
330+ service .stop ();
331+ }
332+ }
333+ }
334+
335+ @ Test public void checkAbilityToBuildServiceWithPortUsingShortFlag () throws Exception {
336+ String port = "8996" ;
337+ String expectedUrl = String .format ("http://0.0.0.0:%s/wd/hub" , port );
338+
339+ AppiumDriverLocalService service = null ;
340+
341+ try {
342+ service = new AppiumServiceBuilder ()
343+ .withArgument (() -> "-p" , port )
344+ .build ();
345+ service .start ();
346+ String actualUrl = service .getUrl ().toString ();
347+ assertEquals (expectedUrl , actualUrl );
348+ } finally {
349+ if (service != null ) {
350+ service .stop ();
351+ }
352+ }
353+ }
354+
355+ @ Test public void checkAbilityToBuildServiceWithIpUsingFlag () throws Exception {
356+ String expectedUrl = String .format ("http://%s:%s/wd/hub" , testIP , 4723 );
357+
358+ AppiumDriverLocalService service = null ;
359+
360+ try {
361+ service = new AppiumServiceBuilder ()
362+ .withArgument (() -> "--address" , testIP )
363+ .build ();
364+ service .start ();
365+ String actualUrl = service .getUrl ().toString ();
366+ assertEquals (expectedUrl , actualUrl );
367+ } finally {
368+ if (service != null ) {
369+ service .stop ();
370+ }
371+ }
372+ }
373+
374+ @ Test public void checkAbilityToBuildServiceWithIpUsingShortFlag () throws Exception {
375+ String expectedUrl = String .format ("http://%s:%s/wd/hub" , testIP , 4723 );
376+
377+ AppiumDriverLocalService service = null ;
378+
379+ try {
380+ service = new AppiumServiceBuilder ()
381+ .withArgument (() -> "-a" , testIP )
382+ .build ();
383+ service .start ();
384+ String actualUrl = service .getUrl ().toString ();
385+ assertEquals (expectedUrl , actualUrl );
386+ } finally {
387+ if (service != null ) {
388+ service .stop ();
389+ }
390+ }
391+ }
392+
393+ @ Test public void checkAbilityToBuildServiceWithLogFileUsingFlag () throws Exception {
394+ AppiumDriverLocalService service = null ;
395+
396+ File log = new File ("Log2.txt" );
397+
398+ try {
399+ service = new AppiumServiceBuilder ()
400+ .withArgument (() -> "--log" , log .getAbsolutePath ())
401+ .build ();
402+ service .start ();
403+ assertTrue (log .exists ());
404+ } finally {
405+ if (service != null ) {
406+ service .stop ();
407+ }
408+ if (log .exists ()) {
409+ log .delete ();
410+ }
411+ }
412+ }
413+
414+ @ Test public void checkAbilityToBuildServiceWithLogFileUsingShortFlag () throws Exception {
415+ AppiumDriverLocalService service = null ;
416+
417+ File log = new File ("Log3.txt" );
418+
419+ try {
420+ service = new AppiumServiceBuilder ()
421+ .withArgument (() -> "-g" , log .getAbsolutePath ())
422+ .build ();
423+ service .start ();
424+ assertTrue (log .exists ());
425+ } finally {
426+ if (service != null ) {
427+ service .stop ();
428+ }
429+ if (log .exists ()) {
430+ log .delete ();
431+ }
432+ }
433+ }
315434}
0 commit comments