如何在Appium中使用JavascriptExecutor

huangapple 未分类评论70阅读模式
英文:

How to work with JavascriptExecutor in Appium

问题

我尝试在Web应用程序中运行自动化测试时,当测试达到需要运行JavascriptExecutor的阶段时,我会遇到以下错误:
>org.openqa.selenium.UnsupportedCommandException: 方法未实现

在尝试运行Appium之前,我确认我可以在尝试运行Appium的同一网站上使用Selenium运行相同的测试。

以下是该函数部分内容:

JavascriptExecutor js = driver;

sleep(2000);
js.executeScript("window.getOutsideInjectedImage = function() {" +
                "console.log('liad Sending');" +
                "const myBlob = new Blob([new Uint8Array(JSON.parse('" + sb.toString() + "')).buffer], {type: 'image/jpg'});" +
                "window.liadBlob = myBlob;" +
                "window.liadSb ='" + sb.toString() + "';" +
                "console.log('liad blob' + myBlob);" +
                "return myBlob;}");

这个函数的作用是在设备的相机打开时将图像注入到服务器中。

英文:

I try to work with JavascriptExecutor when I run an automation test in a web application when the test reaches the stage where I need to run JavascriptExecutor I get an error:
>org.openqa.selenium.UnsupportedCommandException: Method is not implemented

Before I tried running Appium, I checked that I could run the same test in selenium on the same site where I was trying to run Appium

This is the function:

JavascriptExecutor js = driver;

sleep(2000);
js.executeScript("window.getOutsideInjectedImage = function() {" +
                "console.log('liad Sending');" +
                "const myBlob = new Blob([new Uint8Array(JSON.parse('" + sb.toString() + "')).buffer], {type: 'image/jpg'});" +
                "window.liadBlob = myBlob;" +
                "window.liadSb ='" + sb.toString() + "';" +
                "console.log('liad blob' + myBlob);" +
                "return myBlob;}");

What this function does is, inject an image into the server when the device's camera opens.

huangapple
  • 本文由 发表于 2020年7月27日 15:45:00
  • 转载请务必保留本文链接:https://java.coder-hub.com/63110839.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定