In order to integrate Applitools using Selenium Webdriver together with Perfecto, you need to follow the next steps. The following example is a test conducted on the android calculator.
Please note that in order to run the test, you need to set "Perfecto user", "Perfecto password" and "Perfecto host" with Perfecto account variables.
The necessary code you need in order to connect Applitools to Perfecto mobile is:
package com.applitools.Full;
Please note that in order to run the test, you need to set "Perfecto user", "Perfecto password" and "Perfecto host" with Perfecto account variables.
The necessary code you need in order to connect Applitools to Perfecto mobile is:
package com.applitools.Full;
import com.applitools.eyes.Eyes; import io.appium.java_client.remote.MobileCapabilityType; import org.junit.Before; import org.junit.Test; import org.junit.internal.runners.JUnit38ClassRunner; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.DriverCommand; import org.openqa.selenium.remote.RemoteExecuteMethod; import org.openqa.selenium.remote.RemoteWebDriver; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLEncoder; import java.util.Dictionary; import java.util.HashMap; import java.util.Map; @RunWith(JUnit4.class) public class PerfectoNative { private WebDriver driver; private Eyes eyes; @Before public void setup() throws MalformedURLException, UnsupportedEncodingException { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("platformVersion", "4.4.*"); caps.setCapability("platformName", "Android"); caps.setCapability("manufacturer", "HTC"); String user = URLEncoder.encode(PERFECTO_USER, "UTF-8"); String password = URLEncoder.encode(PERFECTO_PASS, "UTF-8"); URL url = new URL("https://" + user + ":" + password + "@"+HOST+".perfectomobile.com/nexperience/wd/hub"); driver = new RemoteWebDriver(url, caps); String commandStartApp = "mobile:application:open"; Map<String, Object> paramsStartApp = new HashMap(); paramsStartApp.put("name", "Calculator"); Object result = ((JavascriptExecutor) driver).executeScript(commandStartApp, paramsStartApp); switchToContext("NATIVE"); eyes = new Eyes(); eyes.setApiKey(APPLITOOLS_API_KEY); } @Test public void test() { try { driver = eyes.open(driver, "calculator", "Perfecto calculator test"); eyes.checkWindow("Initial state"); driver.findElement(By.xpath("//android.widget.ImageButton[@content-desc=\"1\"]")).click(); eyes.checkWindow("1"); driver.findElement(By.xpath("//android.widget.ImageButton[@content-desc=\"plus\"]")).click(); eyes.checkWindow("+"); driver.findElement(By.xpath("//android.widget.ImageButton[@content-desc=\"2\"]")).click(); eyes.checkWindow("2"); driver.findElement(By.xpath("//android.widget.ImageButton[@content-desc=\"plus\"]")).click(); eyes.checkWindow("+"); driver.findElement(By.xpath("//android.widget.ImageButton[@content-desc=\"3\"]")).click(); eyes.checkWindow("3"); driver.findElement(By.xpath("//android.widget.ImageButton[@content-desc=\"equal\"]")).click(); eyes.checkWindow("Result"); eyes.close(); driver.quit(); } finally { eyes.abortIfNotClosed(); } } private void switchToContext(String context) { RemoteExecuteMethod executeMethod = new RemoteExecuteMethod((RemoteWebDriver) driver); Map<String,String> params = new HashMap<String,String>(); params.put("name", context); executeMethod.execute(DriverCommand.SWITCH_TO_CONTEXT, params); } }
Comments
0 comments
Article is closed for comments.