input.test.js 5.1 KB
Newer Older
张磊 已提交
1 2 3 4 5 6 7 8 9 10
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/

describe('component-native-input', () => {

  let page;
  beforeAll(async () => {
    page = await program.reLaunch('/pages/component/input/input')
    await page.waitFor(3000);
  });

张磊 已提交
11 12 13 14 15 16
  it("beforeAllTestScreenshot", async () => {
    const image = await program.screenshot({
      fullPage: true
    })
    expect(image).toMatchImageSnapshot()
  })
张磊 已提交
17 18 19 20
  // 测试焦点及键盘弹起
  it('focus', async () => {
    const input = await page.$('.uni-input-focus');
    expect(await input.property('focus')).toBe(true)
张磊 已提交
21
    expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true)
张磊 已提交
22 23 24 25 26
    await page.setData({
      focus: false,
    })
    expect(await input.property('focus')).toBe(false)
    await page.waitFor(1000)
张磊 已提交
27
    expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false)
张磊 已提交
28 29 30 31 32
    await page.setData({
      focus: true,
    })
    expect(await input.property('focus')).toBe(true)
    await page.waitFor(1000)
张磊 已提交
33
    expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true)
张磊 已提交
34 35 36 37
    await page.setData({
      focus: false,
    })
    expect(await input.property('focus')).toBe(false)
张磊 已提交
38 39 40
    await page.waitFor(1000)
    expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false)
    await page.waitFor(1000)
张磊 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  });

  // 测试修改value属性
  it("value", async () => {
    const input = await page.$('.uni-input-default');
    expect(await input.property('value')).toEqual("hello uni-app x")
  })

  //测试input的类型
  it("type", async () => {
    const text = await page.$('.uni-input-type-text');
    const number = await page.$('.uni-input-type-number');
    const digit = await page.$('.uni-input-type-digit');
    const tel = await page.$('.uni-input-type-tel');
    expect(await text.property('type')).toEqual("text")
    expect(await number.property('type')).toEqual("number")
    expect(await digit.property('type')).toEqual("digit")
    expect(await tel.property('type')).toEqual("tel")
  })

  //  测试密码属性
  it("password", async () => {
    const input = await page.$('.uni-input-password');
    expect(await input.property('password')).toBe(true)
    await page.setData({
      inputPassword: false,
张磊 已提交
67
      inputPasswordValue: "inputPasswordValue"
张磊 已提交
68 69
    })
    expect(await input.property('password')).toBe(false)
张磊 已提交
70 71 72 73
    await page.waitFor(500)
    await page.setData({
      inputPassword: true
    })
张磊 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
  })
  // 测试placeholder
  it("placeholder", async () => {
    const placeholder1 = await page.$('.uni-input-placeholder1');
    expect(await placeholder1.property("placeholder-style")).toMatchObject({
      "color": "red"
    })
    expect(await placeholder1.property("placeholder")).toEqual("占位符文字颜色为红色")
    await page.setData({
      inputPlaceHolderStyle: "color:#CC00CC",
    })
    expect(await placeholder1.property("placeholder-style")).toMatchObject({
      "color": "#CC00CC"
    })

    await page.setData({
      inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0",
    })
    expect(await placeholder1.property("placeholder-style")).toMatchObject({
      "color": "#CC19CC",
      "backgroundColor": "#00b1c0"
    })

    await page.setData({
张磊 已提交
98
      inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0;text-align:center;font-size:44px;font-weight:900",
张磊 已提交
99 100 101 102
    })
    expect(await placeholder1.property("placeholder-style")).toEqual({
      "backgroundColor": "#00b1c0",
      "color": "#CC19CC",
张磊 已提交
103
      "fontSize": "44px",
张磊 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
      "fontWeight": "900",
      "textAlign": "center"
    })

    const placeholder2 = await page.$('.uni-input-placeholder2');
    expect(await placeholder2.property("placeholder-class")).toMatchObject({
      "backgroundColor": "#008000"
    })
    await page.setData({
      inputPlaceHolderClass: "uni-input-placeholder-class-ts",
    })
    expect(await placeholder2.property("placeholder-class")).toMatchObject({
      "backgroundColor": "#FFA500"
    })
    expect(await placeholder2.property("placeholder")).toEqual("占位符背景色为绿色")
  })

  it("disable", async () => {
    const input = await page.$('.uni-input-disable');
    expect(await input.property("disabled")).toBe(true)
  })

  it("confirm-type", async () => {
    expect(await (await page.$('.uni-input-confirm-send')).property("confirmType")).toEqual("send")
    expect(await (await page.$('.uni-input-confirm-search')).property("confirmType")).toEqual("search")
    expect(await (await page.$('.uni-input-confirm-next')).property("confirmType")).toEqual("next")
    expect(await (await page.$('.uni-input-confirm-go')).property("confirmType")).toEqual("go")
    expect(await (await page.$('.uni-input-confirm-done')).property("confirmType")).toEqual("done")
  })
张磊 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

  it("maxlength", async () => {
    const input = await page.$('.uni-input-maxlength');
    await page.setData({
      inputMaxLengthValue: "uni-input-maxlength"
    })
    await page.waitFor(500)
  })

  it("afterAllTestScreenshot", async () => {
    const image = await program.screenshot({
      fullPage: true
    })
    expect(image).toMatchImageSnapshot()
  })
});