input.test.js 7.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
  // it("beforeAllTestScreenshot", async () => {
  //   const image = await program.screenshot({
  //     fullPage: true
  //   })
15
  //   expect(image).toSaveImageSnapshot()
16
  // })
张磊 已提交
17
  // 测试焦点及键盘弹起
18
  it('focus', async () => {
19
    const input = await page.$('#uni-input-focus');
20
    expect(await input.attribute('focus')).toBe("true")
21 22 23 24
    // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true)
    await page.setData({
      focus: false,
    })
25
    expect(await input.attribute('focus')).toBe("false")
26 27 28 29 30
    // await page.waitFor(1000)
    // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false)
    // await page.setData({
    //   focus: true,
    // })
雪洛's avatar
雪洛 已提交
31
    // expect(await input.attribute('focus')).toBe(true)
32 33 34 35 36
    // await page.waitFor(1000)
    // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true)
    // await page.setData({
    //   focus: false,
    // })
雪洛's avatar
雪洛 已提交
37
    // expect(await input.attribute('focus')).toBe(false)
38 39 40 41
    // await page.waitFor(1000)
    // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false)
    // await page.waitFor(1000)
  });
张磊 已提交
42 43 44

  // 测试修改value属性
  it("value", async () => {
45
    const input = await page.$('#uni-input-default');
46
    expect(await input.property('value')).toEqual("hello uni-app x")
张磊 已提交
47 48 49 50
  })

  //测试input的类型
  it("type", async () => {
51 52 53 54
    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');
雪洛's avatar
雪洛 已提交
55 56 57 58
    expect(await text.attribute('type')).toEqual("text")
    expect(await number.attribute('type')).toEqual("number")
    expect(await digit.attribute('type')).toEqual("digit")
    expect(await tel.attribute('type')).toEqual("tel")
张磊 已提交
59 60 61
  })

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

89 90 91
  //   await page.setData({
  //     inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0",
  //   })
雪洛's avatar
雪洛 已提交
92
  //   expect(await placeholder1.attribute("placeholder-style")).toMatchObject({
93 94 95
  //     "color": "#CC19CC",
  //     "backgroundColor": "#00b1c0"
  //   })
张磊 已提交
96

97 98 99
  //   await page.setData({
  //     inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0;text-align:center;font-size:44px;font-weight:900",
  //   })
雪洛's avatar
雪洛 已提交
100
  //   expect(await placeholder1.attribute("placeholder-style")).toEqual({
101 102 103 104 105 106
  //     "backgroundColor": "#00b1c0",
  //     "color": "#CC19CC",
  //     "fontSize": "44px",
  //     "fontWeight": "900",
  //     "textAlign": "center"
  //   })
张磊 已提交
107

108
  //   const placeholder2 = await page.$('.uni-input-placeholder2');
雪洛's avatar
雪洛 已提交
109
  //   expect(await placeholder2.attribute("placeholder-class")).toMatchObject({
110 111 112 113 114
  //     "backgroundColor": "#008000"
  //   })
  //   await page.setData({
  //     inputPlaceHolderClass: "uni-input-placeholder-class-ts",
  //   })
雪洛's avatar
雪洛 已提交
115
  //   expect(await placeholder2.attribute("placeholder-class")).toMatchObject({
116 117
  //     "backgroundColor": "#FFA500"
  //   })
雪洛's avatar
雪洛 已提交
118
  //   expect(await placeholder2.attribute("placeholder")).toEqual("占位符背景色为绿色")
119
  // })
张磊 已提交
120 121

  it("disable", async () => {
122
    const input = await page.$('#uni-input-disable');
雪洛's avatar
雪洛 已提交
123
    expect(await input.attribute("disabled")).toBe("true")
张磊 已提交
124 125 126
  })

  it("confirm-type", async () => {
雪洛's avatar
雪洛 已提交
127 128 129 130 131
    expect(await (await page.$('#uni-input-confirm-send')).attribute("confirmType")).toEqual("send")
    expect(await (await page.$('#uni-input-confirm-search')).attribute("confirmType")).toEqual("search")
    expect(await (await page.$('#uni-input-confirm-next')).attribute("confirmType")).toEqual("next")
    expect(await (await page.$('#uni-input-confirm-go')).attribute("confirmType")).toEqual("go")
    expect(await (await page.$('#uni-input-confirm-done')).attribute("confirmType")).toEqual("done")
张磊 已提交
132
  })
张磊 已提交
133

134 135 136 137 138 139 140
  // it("maxlength", async () => {
  //   const input = await page.$('.uni-input-maxlength');
  //   await page.setData({
  //     inputMaxLengthValue: "uni-input-maxlength"
  //   })
  //   await page.waitFor(500)
  // })
张磊 已提交
141

142 143
  it("cursor-color", async () => {
    await page.setData({
144
      cursor_color: "red",
145 146
    })
    await page.waitFor(500)
147
    expect(await (await page.$('#uni-input-cursor-color')).attribute("cursor-color")).toBe("red")
148 149
  })

150 151
  it("maxlength", async () => {
    const input = await page.$('#uni-input-maxlength');
152
    let str = "";
153
    for (let i = 0; i < 200; i++) {
154 155 156
      str += `${i}`
    }
    await page.setData({
157
      inputMaxLengthValue: str
158
    })
159
    let length = (await input.value()).length
160
    expect(length).toBe(10)
161
    await page.setData({
162
      inputMaxLengthValue: ""
163 164 165
    })
  })

taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
166 167
  it("password and value order", async () => {
    const input = await page.$('#uni-input-password');
168
    let length = (await input.value()).length
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
169 170 171 172 173 174
    expect(length).toBe(6)
    await page.setData({
      inputPasswordValue: ""
    })
  })

175
  it("keyboard height changed after page back", async () => {
176 177
    if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('web')) {
      expect(1).toBe(1)
178 179
      return
    }
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
180
    if (process.env.uniTestPlatformInfo.startsWith('ios')) {
181
      expect(1).toBe(1)
182 183
      return
    }
184
    await program.navigateTo("/pages/API/navigator/new-page/new-page-3")
185 186
    await page.waitFor(2000);
    await program.navigateBack()
DCloud_iOS_WZT's avatar
DCloud_iOS_WZT 已提交
187
    await page.waitFor(2000);
188 189 190
    await page.setData({
      focusedForKeyboardHeightChangeTest: true
    })
191
    await page.waitFor(2000);
192 193 194 195 196 197 198

    const keyboardHeight = await page.data('keyboardHeight');
    console.log("keyboardHeight :", keyboardHeight);
    expect(keyboardHeight).toBeGreaterThan(25)
    //reset
    await page.setData({
      focusedForKeyboardHeightChangeTest: false,
199
      keyboardHeight: 0
200 201 202
    })
  })

203 204 205 206
  it("afterAllTestScreenshot", async () => {
    const image = await program.screenshot({
      fullPage: true
    })
207
    expect(image).toSaveImageSnapshot()
208
  })
209 210 211 212
  it('both set modelValue and value', async () => {
    const input2 = await page.$('#both-model-value');
    expect(await input2.value()).toEqual("123")
  })
张磊 已提交
213
});