Automation test cho Android mobile app với Appium cho người mới bắt đầu (Phần 13) – Viết code (tiếp)

Đoạn code thứ 3 cần chú ý:

capabilities.setCapability(“appPackage”, “vn.com.misa.sothuchi”);

capabilities.setCapability(“appActivity”, “vn.com.misa.sothuchi.SplashActivity”);

driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”;), capabilities);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Dòng 1, 2: Mình sẽ hướng dẫn các bạn lấy Package và Activity của app.

  • Mở thư mục C:\Users\pnmai\AppData\Local\Android\android-sdk\build-tools
  • Chọn một thư mục để mở. Ví dụ 23.0.1

22

  • Giữ chuột trong thư mục đó, ấn Shifl + chuột phải -> Chọn “Open command window here”

23

  • Gõ dòng lệnh “aapt list -a D:\AutomationMobile\AutomationMobile\STC\vn.com.misa.sothuchi.apk >manifest.txt” => nó sẽ sinh ra một file manifest.txt trong cùng thư mục đó.
  • Mở file manifest.txt. Bạn sẽ tìm thấy packageName

24

  • Và tìm thấy activityName (Activity đầu tiên)25

Dòng 3: Các bạn điền server address và port đã note lại ở bước trước.

Dòng 4: Là dòng lệnh mình set timeout.

OK, cuối cùng, sau khi đã hoàn tất, các bạn hãy thử Run ví dụ đầu tiên này về mobile automation test. Chúng ta sẽ còn gặp lại sau. Cám ơn nhiều!

10 bình luận về “Automation test cho Android mobile app với Appium cho người mới bắt đầu (Phần 13) – Viết code (tiếp)

  1. Hiện tại mình đang làm automation bên mảng web, mình đã đọc và làm xong 13 tuts của bạn trong chiều nay, thời gian bạn bỏ ra để viết lại những hướng dẫn này bằng tiếng Việt cũng ko phải là ít. Cám ơn sự chia sẻ, hi vọng đc trao đổi thêm nhiều kiến thức cùng nhau, đây là skype của mình: daominhdam
    Thanks 🙂

    Đã thích bởi 1 người

  2. mình cũng đang nghiên cứu Appium, nhưng và viết testscipt mình chưa biết viết, không biết học thế mào cho hiệu quả, mong được chia sẻ cùng bạn, skype : namlh.asiantech

    Thích

      1. Bài viết rất hay! mình đã làm theo và thanh công. Bạn có thể giợi thiệu hoặc viết bài về cách sử dụng inspector được không bạn ( VÍ dụ: làm thế nào để lấy được các id của các ICON trên UI) ! Cảm ơn bạn rất nhiêu!

        Thích

  3. Bạn ơi ! Trước tiên mình cảm ơn bạn nhiều quá vì đã có 1 seri bài viết vô cùng bổ ích. Mình đã làm theo từng bước tuy nhiên khi run thì mình nhận được thông báo lỗi . Bạn có thể giúp mình được không ?! mình tìm kiếm suốt 1 ngày vẫn không biết xử lí thế nào huhu. Lỗi như sau :

    org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: ‘java -version’ failed. Error: spawn ENOENT) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 506 milliseconds
    Build info: version: ‘2.48.0’, revision: ‘b7b081a’, time: ‘2015-10-07 15:45:39’
    System info: host: ‘Truong-PC’, ip: ‘192.168.56.1’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.8.0_45’
    Driver info: io.appium.java_client.android.AndroidDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142)
    at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:37)
    at io.appium.java_client.AppiumDriver.(AppiumDriver.java:160)
    at io.appium.java_client.AppiumDriver.(AppiumDriver.java:168)
    at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:69)
    at testWithAppium.runTest.setUp(runTest.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

    Thích

  4. Cảm ơn bạn , những bài viết rất bổ ít.
    Tuy nhiên trong quá trình thực hành mình không biết làm sai ở đâu nên bị lỗi . bạn làm ơn giúp dùm nhé.
    Lỗi như sau :
    org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: ‘java -version’ failed. Error: spawn ENOENT) (WARNING: The server did not provide any stacktrace information)

    Thích

Bình luận về bài viết này