我试图添加" if"具有2个替代用例的测试用例的条件,
第一个是 IF 它存在于用户,因此它应该查找" idan+free@gmail.com"在屏幕上,跳过测试用例到下一个,
ELSE - 执行以下操作。
测试用例 -
describe ('Production - New Free Account Test Case', function() {
var EC = protractor.ExpectedConditions;
var dashboardBtn = element(by.xpath('//div/md-sidenav/f-main-menu/div[1]/ul[1]/li[1]/button/div/div[1]/md-icon'));
var noActivation = element(by.linkText("idan+free@gmail.com"));
beforeEach(function() {
browser.ignoreSynchronization = true;
});
afterEach(function() {
browser.ignoreSynchronization = false;
});
it ('Production - Free Account - Activation', function() {
browser.wait(EC.elementToBeClickable(dashboardBtn), 30000);
dashboardBtn.click();
browser.wait(EC.visibilityOf(element(by.css("div.task-header.font-smd.task-clickable.ng-binding.flex"))), 30000);
noActivation.isDisplayed().then(function(isVisible) {
if (isVisible) {
browser.driver.sleep(1000);
console.log("SKIPPED");
} else {
$$("div.task-header.font-smd.task-clickable.ng-binding.flex").get(1).click();
var mainWindow;
browser.driver.getAllWindowHandles().then(
function(handles) {
mainWindow = handles[0]; //at this point there should be only 1 window
}
);
browser.driver.getAllWindowHandles().then(function (handles) {
handles.forEach(function(handle) {
if (handle !== mainWindow) {
browser.driver.switchTo().window(handle)
//-=- switch to iFrame handler -=-
browser.driver.switchTo().defaultContent(); // you are now outside both frames
browser.driver.wait(EC.visibilityOf(element(by.css("div.clean-white-box.short-registration"))), 30000);
browser.driver.sleep(2000);
}
});
});
}
});
});
it ('Production - Free Account - From Activation to pricing table', function() {
noActivation.isDisplayed().then(function(isVisible) {
if (isVisible) {
browser.driver.sleep(1000);
console.log("SKIPPED");
} else {
element(by.id("pivot_user_attributes_password")).sendKeys("password");
element(by.id("pivot_info_business_size")).click();
browser.wait(EC.visibilityOf(element(by.css('option[value="I do not have a business"]'))), 30000);
element(by.css('option[value="I do not have a business"]')).click();
browser.driver.sleep(1000);
element(by.id("pivot_country_name")).click();
browser.wait(EC.visibilityOf(element(by.css('option[value="United States"]'))), 30000);
element(by.css('option[value="United States"]')).click();
browser.driver.sleep(1000);
element(by.id("pivot_phone_info")).sendKeys("1234567890");
element(by.id("pivot_info_is_web_designer_false")).click();
browser.driver.sleep(1000);
element(by.css("input.green-button")).click();
browser.driver.wait(EC.visibilityOf(element(by.css("div.packages"))), 30000);
}
});
});
it ('Production - Free Account - Activation process has been completed', function() {
noActivation.isDisplayed().then(function(isVisible) {
if (isVisible) {
browser.driver.sleep(1000);
console.log("SKIPPED");
} else {
element(by.css("a.upgrade-button.signup-button.free-button")).click();
browser.wait(EC.visibilityOf(element(by.css("div.tasks-container.layout-column"))), 30000);
element(by.xpath("//div/div/div[2]/div/md-content/div[3]/f-tasks/div[2]/div[1]/f-task-block[2]/div/div[2]/div[1]/div[1]")).click();
expect(element(by.css("div.task-header.font-smd.task-clickable.ng-binding.flex")).isDisplayed()).toBe(true);
}
});
});
it ('Production - Free Account - Empty pages - Calendar first launch', function() {
noActivation.isDisplayed().then(function(isVisible) {
if (isVisible) {
browser.driver.sleep(1000);
console.log("SKIPPED");
} else {
browser.driver.getAllWindowHandles().then(function (handles) {
browser.driver.close();
browser.driver.switchTo().window(handles[0]);
});
}
});
});
});
如果用户未退出,则运行测试时出错 -
[31m Production - Free Account - Activation - fail[0m
1) Test cases pul Frontage Sanity Test Production - New Free Account Test C Production - Free Account - Activation
Message:
[31mNoSuchElementError: No element found using locator: By.linkText("idan+free@gmail.com")[0m
Stacktrace:
NoSuchElementError: No element found using locator: By.linkText("idan+free@gmail.com")
at Array.forEach (native)
at runMicrotasksCallback (node.js:337:7)
Error
at [object Object].<anonymous> (/var/lib/jenkins/workspace/Sanity_Testing_node_12_2/testCases/newApp/freeUserTC.js:209:20)
From: Task: Asynchronous test function: it()
Error
at [object Object].<anonymous> (/var/lib/jenkins/workspace/Sanity_Testing_node_12_2/testCases/newApp/freeUserTC.js:205:3)
at Object.<anonymous> (/var/lib/jenkins/workspace/Sanity_Testing_node_12_2/testCases/newApp/freeUserTC.js:1:63)[31m Production - Free Account - From Activation to pricing table - fail[0m
2) Test cases pul Frontage Sanity Test Production - New Free Account Test C Production - Free Account - From Activation to pricing table
Message:
[31mNoSuchElementError: No element found using locator: By.linkText("idan+f.com")[0m
Stacktrace:
NoSuchElementError: No element found using locator: By.linkText("idan+f.com")
at Array.forEach (native)
at runMicrotasksCallback (node.js:337:7)
Error
at [object Object].<anonymous> (/var/lib/jenkins/workspace/Sanity_Testing_node_12_2/testCases/newApp/freeUserTC.js:238:20)
From: Task: Asynchronous test function: it()
Error
at [object Object].<anonymous> (/var/lib/jenkins/workspace/Sanity_Testing_node_12_2/testCases/newApp/freeUserTC.js:237:4)
at Object.<anonymous> (/var/lib/jenkins/workspace/Sanity_Testing_node_12_2/testCases/newApp/freeUserTC.js:1:63)[31m Production - Free Account - Activation process has been completed - fail[0m
元素: -
<div class="email font-xs ng-binding">idan+free@gmail.com</div>
答案 0 :(得分:1)
by.linkText
以及by.partialLinkText
仅适用于 a
元素。
在您的情况下,您有一个div
元素,您需要按文字过滤。你可以选择:
element(by.xpath("//div[. = 'idan+free@gmail.com' and contains(@class, 'email')]"))
element(by.cssContainingText(".email", "idan+free@gmail.com"));