提交 6c8818ea 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

test(input): 放开 android 端测试

上级 ab5e624d
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ // uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('component-native-input', () => { describe('component-native-input', () => {
let page; let page;
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch('/pages/component/input/input') page = await program.reLaunch('/pages/component/input/input')
await page.waitFor(3000); await page.waitFor(3000);
}); });
// it("beforeAllTestScreenshot", async () => { // it("beforeAllTestScreenshot", async () => {
// const image = await program.screenshot({ // const image = await program.screenshot({
// fullPage: true // fullPage: true
// }) // })
// expect(image).toSaveImageSnapshot() // expect(image).toSaveImageSnapshot()
// }) // })
// 测试焦点及键盘弹起 // 测试焦点及键盘弹起
it('focus', async () => { it('focus', async () => {
const input = await page.$('#uni-input-focus'); const input = await page.$('#uni-input-focus');
expect(await input.attribute('focus')).toBe("true") expect(await input.attribute('focus')).toBe("true")
// expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true) // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true)
await page.setData({ await page.setData({
focus: false, focus: false,
}) })
expect(await input.attribute('focus')).toBe("false") expect(await input.attribute('focus')).toBe("false")
// await page.waitFor(1000) // await page.waitFor(1000)
// expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false) // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false)
// await page.setData({ // await page.setData({
// focus: true, // focus: true,
// }) // })
// expect(await input.attribute('focus')).toBe(true) // expect(await input.attribute('focus')).toBe(true)
// await page.waitFor(1000) // await page.waitFor(1000)
// expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true) // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true)
// await page.setData({ // await page.setData({
// focus: false, // focus: false,
// }) // })
// expect(await input.attribute('focus')).toBe(false) // expect(await input.attribute('focus')).toBe(false)
// await page.waitFor(1000) // await page.waitFor(1000)
// expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false) // expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false)
// await page.waitFor(1000) // await page.waitFor(1000)
}); });
// 测试修改value属性 // 测试修改value属性
it("value", async () => { it("value", async () => {
const input = await page.$('#uni-input-default'); const input = await page.$('#uni-input-default');
expect(await input.property('value')).toEqual("hello uni-app x") expect(await input.property('value')).toEqual("hello uni-app x")
}) })
//测试input的类型 //测试input的类型
it("type", async () => { it("type", async () => {
const text = await page.$('#uni-input-type-text'); const text = await page.$('#uni-input-type-text');
const number = await page.$('#uni-input-type-number'); const number = await page.$('#uni-input-type-number');
const digit = await page.$('#uni-input-type-digit'); const digit = await page.$('#uni-input-type-digit');
const tel = await page.$('#uni-input-type-tel'); const tel = await page.$('#uni-input-type-tel');
expect(await text.attribute('type')).toEqual("text") expect(await text.attribute('type')).toEqual("text")
expect(await number.attribute('type')).toEqual("number") expect(await number.attribute('type')).toEqual("number")
expect(await digit.attribute('type')).toEqual("digit") expect(await digit.attribute('type')).toEqual("digit")
expect(await tel.attribute('type')).toEqual("tel") expect(await tel.attribute('type')).toEqual("tel")
}) })
// 测试密码属性 // 测试密码属性
// it("password", async () => { // it("password", async () => {
// const input = await page.$('.uni-input-password'); // const input = await page.$('.uni-input-password');
// expect(await input.attribute('password')).toBe(true) // expect(await input.attribute('password')).toBe(true)
// await page.setData({ // await page.setData({
// inputPassword: false, // inputPassword: false,
// inputPasswordValue: "inputPasswordValue" // inputPasswordValue: "inputPasswordValue"
// }) // })
// expect(await input.attribute('password')).toBe(false) // expect(await input.attribute('password')).toBe(false)
// await page.waitFor(500) // await page.waitFor(500)
// await page.setData({ // await page.setData({
// inputPassword: true // inputPassword: true
// }) // })
// }) // })
// 测试placeholder // 测试placeholder
// it("placeholder", async () => { // it("placeholder", async () => {
// const placeholder1 = await page.$('.uni-input-placeholder1'); // const placeholder1 = await page.$('.uni-input-placeholder1');
// expect(await placeholder1.attribute("placeholder-style")).toMatchObject({ // expect(await placeholder1.attribute("placeholder-style")).toMatchObject({
// "color": "red" // "color": "red"
// }) // })
// expect(await placeholder1.attribute("placeholder")).toEqual("占位符文字颜色为红色") // expect(await placeholder1.attribute("placeholder")).toEqual("占位符文字颜色为红色")
// await page.setData({ // await page.setData({
// inputPlaceHolderStyle: "color:#CC00CC", // inputPlaceHolderStyle: "color:#CC00CC",
// }) // })
// expect(await placeholder1.attribute("placeholder-style")).toMatchObject({ // expect(await placeholder1.attribute("placeholder-style")).toMatchObject({
// "color": "#CC00CC" // "color": "#CC00CC"
// }) // })
// await page.setData({ // await page.setData({
// inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0", // inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0",
// }) // })
// expect(await placeholder1.attribute("placeholder-style")).toMatchObject({ // expect(await placeholder1.attribute("placeholder-style")).toMatchObject({
// "color": "#CC19CC", // "color": "#CC19CC",
// "backgroundColor": "#00b1c0" // "backgroundColor": "#00b1c0"
// }) // })
// await page.setData({ // await page.setData({
// inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0;text-align:center;font-size:44px;font-weight:900", // inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0;text-align:center;font-size:44px;font-weight:900",
// }) // })
// expect(await placeholder1.attribute("placeholder-style")).toEqual({ // expect(await placeholder1.attribute("placeholder-style")).toEqual({
// "backgroundColor": "#00b1c0", // "backgroundColor": "#00b1c0",
// "color": "#CC19CC", // "color": "#CC19CC",
// "fontSize": "44px", // "fontSize": "44px",
// "fontWeight": "900", // "fontWeight": "900",
// "textAlign": "center" // "textAlign": "center"
// }) // })
// const placeholder2 = await page.$('.uni-input-placeholder2'); // const placeholder2 = await page.$('.uni-input-placeholder2');
// expect(await placeholder2.attribute("placeholder-class")).toMatchObject({ // expect(await placeholder2.attribute("placeholder-class")).toMatchObject({
// "backgroundColor": "#008000" // "backgroundColor": "#008000"
// }) // })
// await page.setData({ // await page.setData({
// inputPlaceHolderClass: "uni-input-placeholder-class-ts", // inputPlaceHolderClass: "uni-input-placeholder-class-ts",
// }) // })
// expect(await placeholder2.attribute("placeholder-class")).toMatchObject({ // expect(await placeholder2.attribute("placeholder-class")).toMatchObject({
// "backgroundColor": "#FFA500" // "backgroundColor": "#FFA500"
// }) // })
// expect(await placeholder2.attribute("placeholder")).toEqual("占位符背景色为绿色") // expect(await placeholder2.attribute("placeholder")).toEqual("占位符背景色为绿色")
// }) // })
it("disable", async () => { it("disable", async () => {
const input = await page.$('#uni-input-disable'); const input = await page.$('#uni-input-disable');
expect(await input.attribute("disabled")).toBe("true") expect(await input.attribute("disabled")).toBe("true")
}) })
it("confirm-type", async () => { it("confirm-type", async () => {
expect(await (await page.$('#uni-input-confirm-send')).attribute("confirmType")).toEqual("send") 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-search')).attribute("confirmType")).toEqual("search")
expect(await (await page.$('#uni-input-confirm-next')).attribute("confirmType")).toEqual("next") 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-go')).attribute("confirmType")).toEqual("go")
expect(await (await page.$('#uni-input-confirm-done')).attribute("confirmType")).toEqual("done") expect(await (await page.$('#uni-input-confirm-done')).attribute("confirmType")).toEqual("done")
}) })
// it("maxlength", async () => { // it("maxlength", async () => {
// const input = await page.$('.uni-input-maxlength'); // const input = await page.$('.uni-input-maxlength');
// await page.setData({ // await page.setData({
// inputMaxLengthValue: "uni-input-maxlength" // inputMaxLengthValue: "uni-input-maxlength"
// }) // })
// await page.waitFor(500) // await page.waitFor(500)
// }) // })
it("cursor-color", async () => { it("cursor-color", async () => {
await page.setData({ await page.setData({
cursor_color: "red", cursor_color: "red",
}) })
await page.waitFor(500) await page.waitFor(500)
expect(await (await page.$('#uni-input-cursor-color')).attribute("cursor-color")).toBe("red") expect(await (await page.$('#uni-input-cursor-color')).attribute("cursor-color")).toBe("red")
}) })
it("maxlength", async () => { it("maxlength", async () => {
const input = await page.$('#uni-input-maxlength'); const input = await page.$('#uni-input-maxlength');
let str = ""; let str = "";
for(let i = 0;i < 200;i++){ for (let i = 0; i < 200; i++) {
str += `${i}` str += `${i}`
} }
await page.setData({ await page.setData({
inputMaxLengthValue: str inputMaxLengthValue: str
}) })
let length = (await input.value()).length let length = (await input.value()).length
expect(length).toBe(10) expect(length).toBe(10)
await page.setData({ await page.setData({
inputMaxLengthValue: "" inputMaxLengthValue: ""
}) })
}) })
it("password and value order", async () => { it("password and value order", async () => {
const input = await page.$('#uni-input-password'); const input = await page.$('#uni-input-password');
let length = (await input.value()).length let length = (await input.value()).length
expect(length).toBe(6) expect(length).toBe(6)
await page.setData({ await page.setData({
inputPasswordValue: "" inputPasswordValue: ""
}) })
}) })
it("keyboard height changed after page back", async () => { it("keyboard height changed after page back", async () => {
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('web')) { if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('web')) {
expect(1).toBe(1) expect(1).toBe(1)
return return
} }
if (process.env.uniTestPlatformInfo.startsWith('ios')) { if (process.env.uniTestPlatformInfo.startsWith('ios')) {
expect(1).toBe(1) expect(1).toBe(1)
return return
} }
await program.navigateTo("/pages/API/navigator/new-page/new-page-3") await program.navigateTo("/pages/API/navigator/new-page/new-page-3")
await page.waitFor(2000); await page.waitFor(2000);
await program.navigateBack() await program.navigateBack()
await page.waitFor(1000); await page.waitFor(1000);
await page.setData({ await page.setData({
focusedForKeyboardHeightChangeTest: true focusedForKeyboardHeightChangeTest: true
}) })
await page.waitFor(2000); await page.waitFor(2000);
const keyboardHeight = await page.data('keyboardHeight'); const keyboardHeight = await page.data('keyboardHeight');
console.log("keyboardHeight :", keyboardHeight); console.log("keyboardHeight :", keyboardHeight);
expect(keyboardHeight).toBeGreaterThan(25) expect(keyboardHeight).toBeGreaterThan(25)
//reset //reset
await page.setData({ await page.setData({
focusedForKeyboardHeightChangeTest: false, focusedForKeyboardHeightChangeTest: false,
keyboardHeight:0 keyboardHeight: 0
}) })
}) })
it("afterAllTestScreenshot", async () => { it("afterAllTestScreenshot", async () => {
const image = await program.screenshot({ const image = await program.screenshot({
fullPage: true fullPage: true
}) })
expect(image).toSaveImageSnapshot() expect(image).toSaveImageSnapshot()
}) })
if (!process.env.uniTestPlatformInfo.startsWith('android')) { it('both set modelValue and value', async () => {
// TODO: 暂时规避 android 端测试 const input2 = await page.$('#both-model-value');
it('both set modelValue and value', async()=>{ expect(await input2.value()).toEqual("123")
const input2 = await page.$('#both-model-value'); })
expect(await input2.value()).toEqual("123")
})
}
}); });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册