使用Selenium自动化测试SAP CRM WebClient UI

简介:
<meta charset="utf-8">

package com.xc.crm.test;

import  static  org.junit.Assert.*;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;

import org.openqa.selenium.By;

import  org.openqa.selenium.NoSuchElementException;

import org.openqa.selenium.WebDriver;

import  org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import  org.openqa.selenium.ie.InternetExplorerDriver;

import  org.openqa.selenium.remote.DesiredCapabilities;

import  org.openqa.selenium.support.ui.ExpectedCondition;

import  org.openqa.selenium.support.ui.WebDriverWait;

public  class CRMTest

{

 private WebDriver myDriver;

 private  String  crmURL;

 private  String  mainWindowHandle;

 private  String  popupWindowHandle;

 @Before

 public  void setUp() throws Exception

       {

//     System.setProperty("webdriver.ie.driver","C:\\xiechuan\\30_Software\\02_Selenium\\IEDriverServer_x64_2.26.2\\IEDriverServer.exe");

//            DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();

//     ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);

//            myDriver = new InternetExplorerDriver(ieCapabilities);

 myDriver = new FirefoxDriver();

 crmURL = "https://ldcijerry.corp:44354/sap/bc/bsp/sap/crm_ui_start/default.htm";

       }

 @After

 public  void tearDown() throws Exception

       {

       }

 @Test

 public  void test() throws InterruptedException

       {

              System.out.println("--- Test Start ---");

 // This is for initial the tab in browser

 // myDriver.navigate().to("[http://www.soso.com/](http://www.soso.com/)");

 // Thread.sleep(5000);

 myDriver.navigate().to(crmURL);

              System.out.println("In Testing: Open CRM Logon page");

              Thread.sleep(15000);

 myDriver.findElement(By.id("sap-user")).clear();

 myDriver.findElement(By.id("sap-password")).clear();

 myDriver.findElement(By.id("sap-user")).sendKeys("XIE");

 myDriver.findElement(By.id("sap-password")).sendKeys("Xc12");

 myDriver.findElement(By.cssSelector("span.urBtnCntTxt")).click();

              System.out.println("In Testing: Logon on CRM");

              Thread.sleep(15000);

 myDriver.findElement(By.id("SERVICEPRO")).click();

              System.out.println("In Testing: Click Service Professional");

              Thread.sleep(30000);

 myDriver.switchTo().frame("CRMApplicationFrame");

              Thread.sleep(10000);

 myDriver.switchTo().frame("WorkAreaFrame1");

              Thread.sleep(10000);

              System.out.println("In Testing: Switched to CRMApplicationFrame-WorkAreaFrame1");

 // Create service order

 // AG3

 // myDriver.findElement(By.id("C5_W18_V19_SRV-ORD-DC")).click();

 // QD3

 myDriver.findElement(By.id("C5_W19_V20_SRV-ORD-DC")).click();

              System.out.println("In Testing: Click to create Service Order");

              Thread.sleep(20000);

 // AG3

 // myDriver.findElement(By.id("C31_W109_V112_V113_btrefobjmain_struct.ib_ibase-btn")).click();

 // QD3

 myDriver.findElement(By.id("C32_W114_V117_V118_btrefobjmain_struct.ib_ibase-btn")).click();

              System.out.println("In Testing: Click value help to search IBase");

 mainWindowHandle = myDriver.getWindowHandle();

              System.out.println("In Testing: " + "Main Window: " + mainWindowHandle + " / " + myDriver.getTitle());

              Thread.sleep(10000);

 for (String myHandle : myDriver.getWindowHandles())

              {

                     System.out.println("In Testing: " + "Current Handle: " + myHandle);

 if(!myHandle.equals(mainWindowHandle))

                     {

 popupWindowHandle = myHandle;

 myDriver.switchTo().window(popupWindowHandle);

                           System.out.println("In Testing: " + "Popup Window: " + myDriver.getWindowHandle() + " / " + myDriver.getTitle());

 break;

                     }

              }

 myDriver.switchTo().frame("WorkAreaFrame1");

              System.out.println("In Testing: Switched to pop-up WorkAreaFrame1");

              Thread.sleep(20000);

 // Enter IBase ID

 // AG3

 // myDriver.findElement(By.id("C36_W133_V135_V136_V141_search_parameters[1].VALUE1")).clear();

 // myDriver.findElement(By.id("C36_W133_V135_V136_V141_search_parameters[1].VALUE1")).sendKeys("4448");

 // QD3

 myDriver.findElement(By.id("C37_W137_V139_V140_V145_search_parameters[1].VALUE1")).clear();

 myDriver.findElement(By.id("C37_W137_V139_V140_V145_search_parameters[1].VALUE1")).sendKeys("12");

              System.out.println("In Testing: Pop-up search parameter entered");

 // Click search button

 // AG3

 // myDriver.findElement(By.id("C36_W133_V135_Searchbtn")).click();

 // QD3

 myDriver.findElement(By.id("C37_W137_V139_Searchbtn")).click();

              System.out.println("In Testing: Click search button in Pop-up window");

              Thread.sleep(10000);

 // Select the row in search result

 // AG3

 // myDriver.findElement(By.id("C36_W133_V135_V137_Table_sel_1-rowsel")).click();

 // QD3

 myDriver.findElement(By.id("C37_W137_V139_V141_Table_sel_1-rowsel")).click();

              System.out.println("In Testing: Select search result in Pop-up window");

              Thread.sleep(10000);

              System.out.println("--- Test End ---");

       }

}
相关文章
|
1天前
|
前端开发 测试技术 C++
Python自动化测试面试:unittest、pytest与Selenium详解
【4月更文挑战第19天】本文聚焦Python自动化测试面试,重点讨论unittest、pytest和Selenium三大框架。unittest涉及断言、TestSuite和覆盖率报告;易错点包括测试代码冗余和异常处理。pytest涵盖fixtures、参数化测试和插件系统,要注意避免过度依赖unittest特性。Selenium的核心是WebDriver操作、等待策略和测试报告生成,强调智能等待和元素定位策略。掌握这些关键点将有助于提升面试表现。
6 0
|
3天前
|
Web App开发 JavaScript 前端开发
深入理解自动化测试框架Selenium的设计与实现
【4月更文挑战第20天】 在软件测试领域,自动化测试已成为提升测试效率和确保产品质量的关键手段。Selenium作为一款广泛使用的开源自动化测试框架,其设计精巧且功能强大,为Web应用提供了一种灵活、高效的测试解决方案。本文将深入探讨Selenium的核心架构与实现细节,解析其如何通过模拟用户操作来执行测试用例,以及它如何适应不断变化的Web技术标准。通过对Selenium内部机制的剖析,旨在帮助测试工程师更好地掌握该工具,并在测试实践中发挥其最大效能。
|
4天前
|
前端开发 JavaScript Java
《手把手教你》系列技巧篇(二十五)-java+ selenium自动化测试-FluentWait(详细教程)
【4月更文挑战第17天】其实今天介绍也讲解的也是一种等待的方法,有些童鞋或者小伙伴们会问宏哥,这也是一种等待方法,为什么不在上一篇文章中竹筒倒豆子一股脑的全部说完,反而又在这里单独写了一篇。那是因为这个比较重要,所以宏哥专门为她量身定制了一篇。FluentWait是Selenium中功能强大的一种等待方式,翻译成中文是流畅等待的意思。在介绍FluentWait之前,我们来讨论下为什么需要设置等待,我们前面介绍了隐式等待和显式等待。
27 3
|
6天前
|
Java 测试技术 定位技术
《手把手教你》系列技巧篇(二十三)-java+ selenium自动化测试-webdriver处理浏览器多窗口切换下卷(详细教程)
【4月更文挑战第15天】本文介绍了如何使用Selenium进行浏览器窗口切换以操作不同页面元素。首先,获取浏览器窗口句柄有两种方法:获取所有窗口句柄的集合和获取当前窗口句柄。然后,通过`switchTo().window()`方法切换到目标窗口句柄。在项目实战部分,给出了一个示例,展示了在百度首页、新闻页面和地图页面之间切换并输入文字的操作。最后,文章还探讨了在某些情况下可能出现的问题,并提供了一个简单的本地HTML页面示例来演示窗口切换的正确操作。
27 0
|
7天前
|
敏捷开发 监控 前端开发
深入理解自动化测试框架Selenium的架构与实践
【4月更文挑战第16天】 在现代软件开发过程中,自动化测试已成为确保产品质量和加快迭代速度的关键手段。Selenium作为一种广泛使用的自动化测试工具,其开源、跨平台的特性使得它成为业界的首选之一。本文旨在剖析Selenium的核心架构,并结合实际案例探讨其在复杂Web应用测试中的高效实践方法。通过详细解读Selenium组件间的交互机制以及如何优化测试脚本,我们希望为读者提供深入理解Selenium并有效运用于日常测试工作的参考。
14 1
|
8天前
|
自然语言处理 测试技术 API
深入理解自动化测试框架Selenium的设计理念与实践
【4月更文挑战第15天】 在现代软件开发过程中,自动化测试已成为确保产品质量和加速迭代的关键手段。Selenium作为一种广泛使用的自动化测试框架,提供了对多种浏览器和平台的支持,极大地促进了Web应用的功能测试。本文旨在剖析Selenium的核心设计理念,探讨其在实际项目中的应用,并指出常见的误区及最佳实践,以期帮助测试工程师更高效地利用Selenium进行测试工作。
|
9天前
|
监控 测试技术 API
深入理解自动化测试框架Selenium的设计与实现
【4月更文挑战第14天】在软件开发过程中,自动化测试是确保代码质量、减少人工重复劳动的关键步骤。Selenium作为一款广泛使用的自动化测试工具,提供了对多种浏览器和操作系统的支持。本文将探讨Selenium的核心组件及其架构设计,分析其如何通过WebDriver与浏览器交互,以及它如何支持多种编程语言进行脚本编写。同时,我们还将讨论Selenium Grid的作用以及它如何实现并行测试,以缩短测试周期并提高测试效率。
174 59
|
9天前
|
前端开发 JavaScript Java
《手把手教你》系列技巧篇(十九)-java+ selenium自动化测试-元素定位大法之By css下卷(详细教程)
【4月更文挑战第11天】按计划今天宏哥继续讲解css的定位元素的方法。但是今天最后一种宏哥介绍给大家,了解就可以了,因为实际中很少用。
34 2
|
10天前
|
Web App开发 测试技术 网络安全
|
3月前
|
数据可视化 测试技术 持续交付
自动化测试神器:Python之Pytest库入门使用
自动化测试神器:Python之Pytest库入门使用
99 4