首页 > 解决方案 > 为什么 CrossBrowser 自动脚本在边缘浏览器中引发错误?

问题描述

伙计们,我在 Chrome、FireFox 和 Edge 中进行跨浏览器自动化。我无法在 Edge 浏览器中完成测试脚本。我收到错误消息

"org.openqa.selenium.WebDriverException: Unknown error (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 42 milliseconds
    Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
    System info: host: 'rcktechiess-06', ip: '192.168.1.44', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_171'
    Driver info: org.openqa.selenium.edge.EdgeDriver
    Capabilities [{applicationCacheEnabled=true, InPrivate=false, pageLoadStrategy=normal, platform=ANY, acceptSslCerts=true, browserVersion=42.17134.1.0, platformVersion=10, locationContextEnabled=true, webStorageEnabled=true, browserName=MicrosoftEdge, takesScreenshot=true, takesElementScreenshot=true, platformName=windows}]
    Session ID: B339099D-F7C6-41A7-A6E6-12D22C3D9937

我已附上异常图像。请检查一下

**Test 1 Code Using Testng**

package Crossbrowser;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class Test1 {

    WebDriver driver;

    @BeforeTest

    @Parameters("browser")

    public void setup(String browser) throws Exception
    {
        //Check if parameter passed from TestNG is 'firefox'

        if(browser.equalsIgnoreCase("firefox"))
        {
        //create firefox instance

            driver = new FirefoxDriver();
        }
        //Check if parameter passed as 'chrome'

        else if(browser.equalsIgnoreCase("chrome"))
        {
            //set path to chromedriver.exe

            System.setProperty("webdriver.chrome.driver", "F:\\New folder\\chromedriver.exe");

            //create chrome instance

            driver = new ChromeDriver();
        }

        //Check if parameter passed as 'Edge'

                else if(browser.equalsIgnoreCase("Edge"))
                {
                    //set path to IE.exe

                    System.setProperty("webdriver.edge.driver","F:\\New folder (2)\\MicrosoftWebDriver (1).exe");
                    //create Edge instance

                    driver = new EdgeDriver();

                }
        else
        {
            //If no browser passed throw exception

            throw new Exception("Browser is not correct");
        }

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }

    @Test

    public void testParameterWithXML() throws InterruptedException
    {

        driver.get("http://xxxxxxxxxx/");

        driver.manage().window().maximize();

        driver.findElement(By.xpath("/html[1]/body[1]/div[2]/header[1]/ss-header[1]/div[1]/div[1]/div[1]/span[1]/a[1]")).click();

        Thread.sleep(2000);
        //Find user name
        WebElement userName = driver.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/ss-auth-form[1]/md-card[1]/ss-login-form[1]/div[1]/form[1]/input[1]"));
        //Fill user name
        userName.sendKeys("koushick@rcktechiees.com");
        //Find password
        WebElement password = driver.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/ss-auth-form[1]/md-card[1]/ss-login-form[1]/div[1]/form[1]/input[2]"));
        //Fill password
        password.sendKeys("1234567890");

        Thread.sleep(2000);

        driver.findElement(By.xpath("//form[@name='myForm']//ss-submit-button[@label='Log In']//input[@class='submit']")).click();

        Thread.sleep(1000);

        Test2 obj = PageFactory.initElements(driver, Test2.class);

         Thread.sleep(2000);

         try
         {
             Actions a1 = new Actions(driver);
             a1.moveToElement(obj.getE1()).click(obj.getE2()).build().perform();
         }
         catch(Exception e)
         {
             System.out.println("Can't Click on The Elemnet");
         }

         Thread.sleep(2000);

         try
         {
         Actions a2 = new Actions(driver);
         a2.moveToElement(obj.getE3()).click(obj.getE3()).build().perform();
         }
         catch(Exception e)
         {
             System.out.println("Can't Click");
         }

         Thread.sleep(2000);

         try
         {
             Actions a3 = new Actions(driver);
             a3.moveToElement(obj.getE4()).click(obj.getE5()).build().perform();
         }
         catch(Exception e)
         {
             System.out.println("Can't Click on The Elemnet");
         }

         Thread.sleep(2000);

         obj.getE6().sendKeys("ss@gmail.com");

         Thread.sleep(2000);

         obj.getE7().click();

         Thread.sleep(2000);

         obj.getE8().click();

         Thread.sleep(2000);


       driver.navigate().to("http://XXXXXXXXXXXX/");

       Thread.sleep(2000);

       driver.findElement(By.xpath("//a[@classname='nav-link men']")).click();

       Thread.sleep(2000);

        }


    @AfterTest
    public void MatchitnowWithXML() throws InterruptedException
    {

        Test2 obj1 = PageFactory.initElements(driver, Test2.class);

         Actions a4 = new Actions(driver);
          a4.moveToElement(obj1.getE9()).click(obj1.getE9()).build().perform();

          Thread.sleep(2000);

          obj1.getE10().click();

          Thread.sleep(2000);

          obj1.getE11().click();

          Thread.sleep(2000);

          JavascriptExecutor js = (JavascriptExecutor) driver;
          js.executeScript("arguments[0].scrollTop = arguments[1];",driver.findElement(By.id("sylnk-it")), 500);

          Thread.sleep(2000);

          obj1.getE12().click();

          Thread.sleep(2000);

          Actions a5 = new Actions(driver);
          a5.moveToElement(obj1.getE13()).click(obj1.getE13()).build().perform();

          Thread.sleep(2000);

          try
          {
          driver.findElement(By.xpath("//button[@class='cal-sly']")).click();
          }
          catch (Exception e)
          {
              System.out.println("Not Visible To Click");
          }

          Thread.sleep(2000);

          driver.navigate().back();

          Thread.sleep(2000);

          driver.navigate().back();

          Thread.sleep(2000);

          try
          {
          Actions a6 = new Actions(driver);
          a6.moveToElement(obj1.getE14()).click(obj1.getE15()).build().perform();
          }
          catch(Exception e)
          {
              System.out.println("Can't Move To The Element and Click");
          }

        Thread.sleep(2000);

        try
        {
            Actions a7 = new Actions(driver);
            a7.moveToElement(obj1.getE16()).click(obj1.getE17()).build().perform();
        }
        catch(Exception e)
        {
            System.out.println("Can't Click on the Element !");
        }

        Thread.sleep(3000);

          JavascriptExecutor jse = (JavascriptExecutor) driver;
          jse.executeScript("window.scrollBy(0,250)"); 

          Thread.sleep(1000);

          try
          {
              Actions a8 = new Actions(driver);
              a8.moveToElement(obj1.getE18()).click(obj1.getE19()).build().perform();
          }
          catch(Exception e)
          {
              System.out.println("Can't Move To The Element and Click");
          }

          Thread.sleep(2000);



        try
        {

            Actions a9 = new Actions(driver);
            a9.moveToElement(obj1.getE20()).click().build().perform();
        }
        catch(Exception e)
        {
            System.out.println("Can't Click");
        }

        Thread.sleep(2000);

        try
        {
            driver.findElement(By.xpath("/html[1]/body[1]/div[2]/ss-app[1]/ss-search-page[1]/div[2]/ss-search-filters[1]/ss-slide-filter[1]/ss-search-filter[1]/div[1]/div[2]/span[1]")).click();
        }
        catch(Exception e)
        {
            System.out.println("Can't Click");
        }




    }


    }

Down am Attaching Page ObjectModel 框架代码

**Test2 Code Using POM Framework Using GET Method**

    package Crossbrowser;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class Test2 {

    public WebElement getE1() {
        return e1;
    }

    public WebElement getE2() {
        return e2;
    }

    public WebElement getE3() {
        return e3;
    }

    public WebElement getE4() {
        return e4;
    }

    public WebElement getE5() {
        return e5;
    }


    public WebElement getE6() {
        return e6;
    }

    public WebElement getE7() {
        return e7;
    }


    public WebElement getE8() {
        return e8;
    }

     public WebElement getE9() {
        return e9;
    }

    public WebElement getE10() {
        return e10;
    }

    public WebElement getE11() {
        return e11;
    }

    public WebElement getE12() {
        return e12;
    }


    public WebElement getE13() {
        return e13;
    }

    public WebElement getE14() {
        return e14;
    }

    public WebElement getE15() {
        return e15;
    }

    public WebElement getE16() {
        return e16;
    } 

    public WebElement getE17() {
        return e17;
    }

    public WebElement getE18() {
        return e18;
    }

    public WebElement getE19() {
        return e19;
    }

    public WebElement getE20() {
        return e20;
    }



    @FindBy(xpath="/html[1]/body[1]/div[2]/header[1]/ss-header[1]/div[1]/div[1]/ss-user-dropdown[1]/div[1]/ss-svg-icon[1]/span[1]/i[1]")
    private WebElement e1;


    @FindBy(xpath="/html[1]/body[1]/div[2]/header[1]/ss-header[1]/div[1]/div[1]/ss-user-dropdown[1]/div[1]/div[1]/a[9]")
    private WebElement e2;


    @FindBy(xpath="//button[@id='ranomizeButton']")
    private WebElement e3;


    @FindBy(xpath="/html/body/div[2]/header/ss-header/div/div[2]/ss-user-dropdown/div")
    private WebElement e4;


    @FindBy(xpath="/html/body/div[2]/header/ss-header/div/div[2]/ss-user-dropdown/div/div/a[3]")
    private WebElement e5;


    @FindBy(xpath="/html[1]/body[1]/div[2]/div[4]/div[2]/div[1]/div[2]/div[2]/div[1]/div[1]/input[1]")
    private WebElement e6;


    @FindBy(xpath="/html[1]/body[1]/div[2]/div[4]/div[2]/div[1]/div[2]/div[2]/div[1]/button[1]")
    private WebElement e7;

    @FindBy(xpath="/html[1]/body[1]/div[2]/div[5]/div[1]/div[1]/div[2]/div[1]/div[1]/button[1]")
    private WebElement e8;


    @FindBy(xpath="/html/body/div[2]/ss-app/ss-search-page/div[4]/div[2]/ss-products-list/div[2]/span[3]/ss-product-cell/div/div[4]/span")
     private WebElement e9;


    @FindBy(xpath="/html/body/div[2]/ss-app/div[6]/div/ss-auth-form/md-card/div[1]/span[1]/div/div[2]/label/span")
    private WebElement e10;


    @FindBy(id="C5")
    private WebElement e11;


    @FindBy(id="slynk_save")
    private WebElement e12;


    @FindBy(xpath="/html[1]/body[1]/div[2]/ss-app[1]/ss-header[1]/div[1]/div[1]/span[2]")
    private WebElement e13;


    @FindBy(xpath="/html[1]/body[1]/div[2]/ss-app[1]/ss-search-page[1]/div[4]/div[2]/ss-products-list[1]/div[2]/span[1]/ss-product-cell[1]/div[1]/div[5]")
    private WebElement e14;


    @FindBy(xpath="/html[1]/body[1]/div[2]/ss-app[1]/ss-search-page[1]/div[4]/div[2]/ss-products-list[1]/div[2]/span[1]/ss-product-cell[1]/div[1]/div[5]/a[2]/span[1]/i[1]")
    private WebElement e15;


    @FindBy(xpath="//ss-product-cell[@id='110743~Dresslily~womens-tops~womens-tops']//div[@class='product-cell-container extended-cell']//div[@class='bottom-icons']")
    private WebElement e16;


    @FindBy(xpath="//span[@id='~110743~Stylish Lace Embellished Short Sleeve Scoop Neck Womens TShirt~Dresslily~Dresslily~Dresslily~womens-tops~womens-tops~~undefined~$4.99~$9.67~~^^womens-tops^womens-clothes^women ']//i[@class='icon-12']")
    private WebElement e17;


    @FindBy(xpath="//ss-product-cell[@id='304028~GuessFactory~shorts~shorts']//div[@class='product-cell-container extended-cell']//div[@class='bottom-icons']")
    private WebElement e18;


    @FindBy(xpath="//span[@id='~304028~Shelby Denim Shorts~GuessFactory~Guess Factory~Guess Factory~shorts~shorts~~undefined~~$44.99~~^^shorts^womens-clothes^women ']//i[@class='icon-12']")
    private WebElement e19;


    @FindBy(xpath="/html[1]/body[1]/div[2]/ss-app[1]/ss-search-page[1]/div[2]/ss-search-filters[1]/ss-slide-filter[1]/ss-search-filter[1]/span[1]")
    private WebElement e20;

PS:在执行测试脚本时,Chrome 和 FireFox 成功通过。但是只有在自动化中间出现某种堆栈错误时才在边缘失败。下来我也在附加 XML 请给我一个解决方案以找到一个 BetterWay。

  <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" >

  <test name="FirefoxTest">
  <parameter name="browser" value="firefox">
    <classes>
      <class name="Crossbrowser.Test1"/>
    </classes>
     </parameter>
     </test> <!-- Test -->

     <test name="chromeTest">
  <parameter name="browser" value="chrome">
    <classes>
      <class name="Crossbrowser.Test1"/>
    </classes>
     </parameter>
     </test> <!-- Test -->

      <test name="EdgeTest">
  <parameter name="browser" value="Edge">
    <classes>
      <class name="Crossbrowser.Test1"/>
    </classes>
     </parameter>
     </test> <!-- Test -->



</suite> <!-- Suite -->

标签: seleniumtestingselenium-webdrivertestng

解决方案


推荐阅读