• 使用 Java 语言
    • 示例集合
    • 用法示例
    • API 文档

    使用 Java 语言

    请使用如下最新版本

    Download

    示例集合

    • 各端Java用例写法示例
    • 架构合理并封装大量实用功能的示例

    用法示例

    1. package macaca.client;
    2. import static org.hamcrest.Matchers.containsString;
    3. import org.apache.log4j.Logger;
    4. import org.junit.After;
    5. import org.junit.Assert;
    6. import org.junit.Before;
    7. import org.junit.Test;
    8. import com.alibaba.fastjson.JSONObject;
    9. import macaca.client.MacacaClient;
    10. public class SampleTest {
    11. MacacaClient driver = new MacacaClient();
    12. @Before
    13. public void setUp() throws Exception {
    14. Logger logger = Logger.getLogger(getClass());
    15. JSONObject porps = new JSONObject();
    16. porps.put("autoAcceptAlerts", true);
    17. porps.put("browserName", "electron");
    18. porps.put("platformName", "desktop"); // android or ios
    19. porps.put("javascriptEnabled", true);
    20. porps.put("platform", "ANY");
    21. //porps.put("app", "path/to/app");
    22. JSONObject desiredCapabilities = new JSONObject();
    23. desiredCapabilities.put("desiredCapabilities", porps);
    24. driver.initDriver(desiredCapabilities)
    25. .setWindowSize(1280, 800)
    26. .get("https://macacajs.github.io/");
    27. }
    28. @Test
    29. public void test_case_1() throws Exception {
    30. driver
    31. .elementById("kw")
    32. .sendKeys("macaca")
    33. .sleep(1000)
    34. .elementById("su")
    35. .click();
    36. String html = driver.source();
    37. Assert.assertThat(html, containsString("macaca"));
    38. }
    39. @Test
    40. public void test_case_2() throws Exception {
    41. System.out.println("test case #2");
    42. }
    43. @After
    44. public void tearDown() throws Exception {
    45. driver.quit();
    46. }
    47. }

    API 文档

    API文档请见文档链接

    原文: https://macacajs.github.io/zh/java